MCPcopy Create free account
hub / github.com/delinoio/oss / GetTaskStateByTaskKey

Method GetTaskStateByTaskKey

cmds/ttlc/internal/cache/sqlite.go:238–341  ·  view source on GitHub ↗
(taskKey string)

Source from the content-addressed store, hash-verified

236}
237
238func (s *Store) GetTaskStateByTaskKey(taskKey string) (TaskState, bool, error) {
239 if s == nil || s.db == nil {
240 return TaskState{}, false, fmt.Errorf("cache store is not initialized")
241 }
242 if strings.TrimSpace(taskKey) == "" {
243 return TaskState{}, false, fmt.Errorf("task key is required")
244 }
245
246 row := s.db.QueryRow(`
247 SELECT task_key, module, task_id, input_content_hash, parameter_hash, environment_snapshot_hash, input_fingerprint, output_blob_ref, deps, metadata, updated_at
248 FROM task_cache
249 WHERE task_key = ?
250 LIMIT 1
251 `, taskKey)
252
253 state := TaskState{}
254 var depsJSON string
255 var metadataJSON string
256 var updatedAt string
257 err := row.Scan(
258 &state.TaskKey,
259 &state.Module,
260 &state.TaskID,
261 &state.InputContentHash,
262 &state.ParameterHash,
263 &state.EnvironmentSnapshotHash,
264 &state.InputFingerprint,
265 &state.OutputBlobRef,
266 &depsJSON,
267 &metadataJSON,
268 &updatedAt,
269 )
270 if err == sql.ErrNoRows {
271 return TaskState{}, false, nil
272 }
273 if err != nil {
274 return TaskState{}, false, fmt.Errorf("query task cache state by task key: %w", err)
275 }
276
277 if unmarshalErr := json.Unmarshal([]byte(depsJSON), &state.Deps); unmarshalErr != nil {
278 return TaskState{}, true, &CorruptionError{
279 Module: state.Module,
280 TaskID: state.TaskID,
281 Field: "deps",
282 Err: unmarshalErr,
283 }
284 }
285 metadataDecoder := json.NewDecoder(strings.NewReader(metadataJSON))
286 metadataDecoder.UseNumber()
287 if decodeErr := metadataDecoder.Decode(&state.Metadata); decodeErr != nil {
288 return TaskState{}, true, &CorruptionError{
289 Module: state.Module,
290 TaskID: state.TaskID,
291 Field: "metadata",
292 Err: decodeErr,
293 }
294 }
295 trailing := struct{}{}

Callers 2

RunMethod · 0.80

Calls

no outgoing calls

Tested by 1