Fix dies_at attribute#57
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes pgqueue task-expiration semantics so dies_at is no longer computed at insertion time, but is instead set when a worker locks a task. This aligns expiration with actual processing start time and updates status/lock/retry behavior accordingly.
Changes:
- Make
task.dies_atnullable and stop setting it inqueue_insert. - Update
queue_task_statusto only mark tasks expired when they are in-progress anddies_atis set and in the past. - Update
queue_lockto setdies_at = NOW() + queue.ttlon lock; resetdies_atto NULL on retry inqueue_fail.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Coverage for this change: 12.4% |
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.
This pull request updates the way the
dies_at(task expiration) field is handled in thepgqueueschema. The main change is to makedies_atnullable on task creation and only set it when a worker actually locks a task, rather than at insertion. This allows for more accurate expiration timing and simplifies the task lifecycle. The logic for determining task status and handling retries has also been updated to accommodate this change.Schema and logic changes for task expiration (
dies_at):dies_atcolumn in thetasktable is now nullable and is no longer set during task insertion; instead, it is set when a worker locks the task. [1] [2]queue_task_statusfor marking a task as expired now checks thatdies_atis not null and only considers tasks in-progress (started but not finished) as expired if theirdies_atis in the past.queue_lockfunction now setsdies_atto the current time plus the queue TTL when a worker locks a task, ensuring expiration is based on actual processing start time. [1] [2]queue_failfunction now resetsdies_atto NULL when a task is retried, so expiration will be recalculated on the next lock.Code and data integrity improvements:
dies_atto NOT NULL after backfilling, sincedies_atis now managed dynamically.queue_lockfunction no longer filters for tasks withdies_at > NOW(), since expiration is now set at lock time, not before.