MCPcopy Create free account
hub / github.com/AS-AIGC/TranscriptHub / cleanup_task_

Function cleanup_task_

apps/backend/services/task_service.js:357–396  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

355
356
357async function cleanup_task_() {
358 //const worker_pids_array = Array.from(worker_pids); // convert Set to Array
359
360 //const pids_for_query = process_sync_worker_pids.join(',');
361 const pids_for_query = get_worker_pids().join(','); // note
362 //logger(LOG_LEVEL.INFO, `PIDs: ${process_sync_worker_pids}`);
363
364
365 let where_pid_clause = '';
366
367 if (pids_for_query.length > 0) {
368 where_pid_clause = `AND (PID IS NULL OR PID NOT IN (${pids_for_query}))`;
369 } else {
370 // where_pid_clause = `AND PID IS NULL`;
371 return logger(LOG_LEVEL.ERROR, `cleanup_task pids_for_query is empty.`, memo);
372 }
373
374 // set status = UPDATE_STATUS.TERMINATED
375 const query = `
376 UPDATE TASK
377 SET STATUS = -2,
378 PID = ${process.pid},
379 RETRY = RETRY - 1
380 WHERE STATUS IN (0, 1, -3)
381 AND FINISH_AT IS NULL
382 ${where_pid_clause};
383 `;
384 // AND (PID IS NULL OR PID NOT IN (${pids_for_query}));
385 const memo = operation_memo({});
386 try {
387 const pool = await pool_promise;
388 const result = await pool.request().query(query);
389
390 if (result.rowsAffected[0] > 0) {
391 logger(LOG_LEVEL.INFO, `cleanup_task clean up ${result.rowsAffected[0]} records.`, memo);
392 }
393 } catch (err) {
394 logger(LOG_LEVEL.ERROR, `cleanup_task ${err}.`, memo);
395 }
396}
397
398/**
399 * @brief Update transcription task status and details

Callers

nothing calls this directly

Calls 3

get_worker_pidsFunction · 0.85
loggerFunction · 0.85
operation_memoFunction · 0.85

Tested by

no test coverage detected