mirror of
https://github.com/hansjone/dsh-ops-cron.git
synced 2026-10-13 04:40:47 +08:00
Allow cron_retrigger to immediately fire recurring jobs.
Recurring tasks can start one extra run now without changing the cron schedule; delay remains oneshot-only. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
c11221606a
commit
3ce60b200c
5 changed files with 58 additions and 21 deletions
26
lib/host.js
26
lib/host.js
|
|
@ -701,9 +701,10 @@ export function createHostService(options = {}) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Re-arm a consumed one-shot job.
|
||||
* afterMinutes omitted/0 → immediate run-now; >0 → reschedule next and wait for tick.
|
||||
* Auto-enables paused jobs. Rejects cron jobs and in-flight/pending-next oneshots.
|
||||
* Fire an extra run, or re-arm a consumed one-shot.
|
||||
* - recurring (cron): after_minutes must be 0/omitted → enable + immediate run-now (keeps cron next)
|
||||
* - one-shot (at): consumed only; 0 → run-now; >0 → reschedule next
|
||||
* Auto-enables paused jobs. Rejects when a run is already pending/running.
|
||||
*/
|
||||
async function retriggerJob(jobId, opts = {}, identity = null) {
|
||||
const afterRaw = opts.afterMinutes ?? opts.after_minutes
|
||||
|
|
@ -727,8 +728,9 @@ export function createHostService(options = {}) {
|
|||
throw error
|
||||
}
|
||||
if (identity) assertCanAccessJob(job, identity)
|
||||
if (job.schedule?.kind !== 'at') {
|
||||
const error = new Error('cron_retrigger is only for one-shot (at) jobs; use pause/resume for recurring jobs')
|
||||
const kind = job.schedule?.kind
|
||||
if (kind !== 'at' && kind !== 'cron') {
|
||||
const error = new Error('cron_retrigger requires a one-shot (at) or recurring (cron) job')
|
||||
error.code = 'INVALID_RETRIGGER'
|
||||
throw error
|
||||
}
|
||||
|
|
@ -738,6 +740,20 @@ export function createHostService(options = {}) {
|
|||
error.code = 'ALREADY_RUNNING'
|
||||
throw error
|
||||
}
|
||||
|
||||
if (kind === 'cron') {
|
||||
if (delayMs > 0) {
|
||||
const error = new Error('after_minutes delay is only for one-shot jobs; omit it to fire a recurring job immediately')
|
||||
error.code = 'INVALID_RETRIGGER'
|
||||
throw error
|
||||
}
|
||||
if (job.enabled === false) {
|
||||
return upsertJob(current, { ...job, enabled: true, updatedAt: t })
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
// one-shot
|
||||
if (job.nextRunAt != null) {
|
||||
const error = new Error('one-shot still has a pending next run; wait or edit the schedule instead of retrigger')
|
||||
error.code = 'INVALID_RETRIGGER'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue