Repository navigation
Keep recurring tasks running after a worker dies mid-run - #555
Closed
evantahler wants to merge 1 commit into
Closed
evantahler wants to merge 1 commit into
evantahler wants to merge 1 commit into
Conversation
Recurring tasks used node-resque's JobLock with an hour-long lock and reEnqueue: false. If a process died mid-run, the orphaned lock made the next boot's enqueue get refused and dropped, which ended the recurring chain until the lock expired. - Replace JobLock with RecurringTaskLock: a short lease (config.tasks.recurringLockTimeout, 15s) renewed while the job runs, which re-arms the chain when it refuses a run. - Run QueueLock first so its lock is released on pop even when the run is refused. - When an initializer fails during api.start(), stop the initializers that started (best-effort) before throwing. closes #554 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015fc4xNZMVrBPdBEhZpgNCR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #554
Problem
Recurring tasks (
task.frequency) used node-resque'sJobLockwith a 1-hour lock andreEnqueue: false. If a process died mid-run (a failed initializerstart(), OOM, SIGKILL), itsworkerslockkey stayed behind. On the next boot,enqueueAllRecurrent()enqueued the job,JobLockrefused it and dropped it, and the perform wrapper'sfinally→enqueueRecurrent()never ran. The clock stayed silent until the lock expired, and after that it stayed silent until the next boot.Changes
RecurringTaskLockplugin (packages/keryx/util/recurringTaskLock.ts) replacesJobLockfor recurring tasks:config.tasks.recurringLockTimeout, default 15 s, envTASK_RECURRING_LOCK_TIMEOUT) with a per-run token. The lease is renewed every third of its length while the job runs and released (token-checked) inafterPerform. A dead worker's lock now lapses within one lease, not an hour.api.actions.enqueueRecurrent(action), so the task is retried everyfrequencyinstead of being dropped.JobLock, so a lock left by an older version still prevents an overlapping run during an upgrade.QueueLocknow runs before the run lock, so the queue lock is released as soon as the job is popped. Before, a refused run left a staleresque:lock:*key that would also have blocked the re-enqueue for an hour.api.start()cleanup: when an initializer'sstart()throws, the initializers that already started (plus the one that failed) are stopped in reverse order, best-effort, before theSERVER_STARTerror is thrown. A failed boot no longer leaves resque workers to die mid-job.recurringLockTimeoutto the config table and a short note in the tasks guide.Tests
resque.test.ts: a recurring task with an orphaned lock (simulating a dead worker) runs once the lease lapses. This test fails onmain. A second test checks that the lock is renewed through a run several leases long and that no second run overlaps it, with 2 workers.API.test.ts: a failed start stops the started initializers in reverse order, skips the ones that never started, and still surfaces the start error when astop()also throws.oauthHandlers"unreachable document", also fails onmainin my sandbox because of its network proxy.Generated by Claude Code