1
This commit is contained in:
@@ -43,7 +43,7 @@ async function run_cron_task(task) {
|
||||
async function run_cron_task_with_guard(task_name, task) {
|
||||
if (running_task_name_set.has(task_name)) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[cron] skip (already running)', { name: task_name });
|
||||
console.log(`[${new Date().toLocaleString()}] [cron] skip (already running)`, { name: task_name });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,8 @@ async function run_cron_task_with_guard(task_name, task) {
|
||||
try {
|
||||
await run_cron_task(task);
|
||||
} catch (error) {
|
||||
console.warn('[cron] error', { task_name, error });
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(`[${new Date().toLocaleString()}] [cron] error`, { task_name, error });
|
||||
} finally {
|
||||
running_task_name_set.delete(task_name);
|
||||
}
|
||||
@@ -66,13 +67,14 @@ export async function start_all_cron_tasks() {
|
||||
const job = cron.schedule(task.cron_expression, async () => {
|
||||
await run_cron_task_with_guard(task_name, task);
|
||||
});
|
||||
console.log('job', { task_name, });
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`[${new Date().toLocaleString()}] job`, { task_name });
|
||||
cron_jobs.push(job);
|
||||
|
||||
if (run_now) {
|
||||
// 启动时额外立刻跑一次(仍走 guard,避免与 cron 触发撞车)
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[cron] run_now', { task_name });
|
||||
console.log(`[${new Date().toLocaleString()}] [cron] run_now`, { task_name });
|
||||
await run_cron_task_with_guard(task_name, task);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user