Skip to content

Fix dies_at attribute#57

Merged
djthorpe merged 3 commits into
mainfrom
djt/0617/dies_at_fix
Jun 17, 2026
Merged

Fix dies_at attribute#57
djthorpe merged 3 commits into
mainfrom
djt/0617/dies_at_fix

Conversation

@djthorpe

Copy link
Copy Markdown
Member

This pull request updates the way the dies_at (task expiration) field is handled in the pgqueue schema. The main change is to make dies_at nullable 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):

  • The dies_at column in the task table is now nullable and is no longer set during task insertion; instead, it is set when a worker locks the task. [1] [2]
  • The logic in queue_task_status for marking a task as expired now checks that dies_at is not null and only considers tasks in-progress (started but not finished) as expired if their dies_at is in the past.
  • The queue_lock function now sets dies_at to the current time plus the queue TTL when a worker locks a task, ensuring expiration is based on actual processing start time. [1] [2]
  • The queue_fail function now resets dies_at to NULL when a task is retried, so expiration will be recalculated on the next lock.

Code and data integrity improvements:

  • Removed the previous migration logic and constraint that forcibly set dies_at to NOT NULL after backfilling, since dies_at is now managed dynamically.
  • The queue_lock function no longer filters for tasks with dies_at > NOW(), since expiration is now set at lock time, not before.

Copilot AI review requested due to automatic review settings June 17, 2026 10:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_at nullable and stop setting it in queue_insert.
  • Update queue_task_status to only mark tasks expired when they are in-progress and dies_at is set and in the past.
  • Update queue_lock to set dies_at = NOW() + queue.ttl on lock; reset dies_at to NULL on retry in queue_fail.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pgqueue/schema/objects.sql
Comment thread pgqueue/schema/objects.sql
@github-actions

Copy link
Copy Markdown

Coverage for this change: 12.4%

@djthorpe djthorpe merged commit 1e15209 into main Jun 17, 2026
2 checks passed
@djthorpe djthorpe deleted the djt/0617/dies_at_fix branch June 17, 2026 11:21
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.

2 participants