mirror of
https://github.com/hansjone/dsh-ops-cron.git
synced 2026-10-10 22:20:47 +08:00
Add cron_retrigger for consumed one-shot jobs.
Resume only unpauses; listeners need a native way to re-fire the same job id with a new run without creating duplicate executors. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
6724332114
commit
c11221606a
9 changed files with 324 additions and 7 deletions
|
|
@ -226,6 +226,24 @@ export function persistHistoryLimit(policy, settingsLimit = 200) {
|
|||
return settingsLimit
|
||||
}
|
||||
|
||||
/**
|
||||
* One-shot job whose schedule has been consumed (next cleared) and has a terminal lastStatus.
|
||||
* Used by listeners to decide cron_retrigger vs wait.
|
||||
* @param {object|null} job
|
||||
* @param {object[]} [runs]
|
||||
*/
|
||||
export function isRetriggerable(job, runs = []) {
|
||||
if (!job || job.schedule?.kind !== 'at') return false
|
||||
if (job.nextRunAt != null) return false
|
||||
const terminal = job.lastStatus === 'succeeded'
|
||||
|| job.lastStatus === 'failed'
|
||||
|| job.lastStatus === 'skipped'
|
||||
if (!terminal) return false
|
||||
const list = Array.isArray(runs) ? runs : []
|
||||
if (list.some((run) => run && ACTIVE_RUN_STATUSES.has(run.status))) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Project job + runs into a lifecycle state for listeners.
|
||||
* @param {object} job
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue