Skip to content

Add renew_org_task_lock so org tasks can hold short, renewable locks - #267

Draft
norkans7 wants to merge 1 commit into
mainfrom
org-task-lock-renewal
Draft

Add renew_org_task_lock so org tasks can hold short, renewable locks#267
norkans7 wants to merge 1 commit into
mainfrom
org-task-lock-renewal

Conversation

@norkans7

@norkans7 norkans7 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant