Add renew_org_task_lock so org tasks can hold short, renewable locks - #267
Draft
norkans7 wants to merge 1 commit into
Draft
Add renew_org_task_lock so org tasks can hold short, renewable locks#267norkans7 wants to merge 1 commit into
norkans7 wants to merge 1 commit into
Conversation
An org task's lock timeout previously had to cover its worst-case full runtime, so a hard-killed worker left the org locked for hours. Tasks that checkpoint their progress can now call renew_org_task_lock() after each unit of work and pass a lock_timeout that only needs to outlive one unit - a killed worker then frees the org after one short lease. The call returns False when the lease was already lost, letting the task stop cleanly instead of running concurrently with its replacement.
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.
An org task's lock timeout has to cover its worst-case full runtime, which means a hard-killed worker (one that never runs its `finally` block) leaves the org locked — and the task silenced — for up to that timeout, hours in practice.
This adds `renew_org_task_lock()`: the running task's lock is kept in a thread-local, and a task that checkpoints its progress can renew the lease after each unit of work. Such tasks can then be declared with a `lock_timeout` that only needs to outlive a single unit — a killed worker frees the org after one short lease instead of hours, while a healthy long run keeps its lock alive indefinitely.
The call returns `False` when the lease was already lost (expired and possibly re-acquired by a replacement worker), so the task can stop cleanly instead of running concurrently with its successor. Outside a running org task it is a no-op returning `True`, so shared library code can call it unconditionally.
No behavior change for existing tasks that don't call it.