Skip to content

Added permanent failure support#59

Merged
djthorpe merged 4 commits into
mainfrom
djt/0617/fail
Jun 17, 2026
Merged

Added permanent failure support#59
djthorpe merged 4 commits into
mainfrom
djt/0617/fail

Conversation

@djthorpe

Copy link
Copy Markdown
Member

This pull request introduces improvements to task queue management in the pgqueue package, focusing on more robust handling of expired running tasks and ensuring partitions are available before task insertion. It also adds new tests to verify correct behavior when tasks exceed their TTL and when expired tasks are reclaimed, and updates the SQL schema to support these changes.

Task execution and timeout handling:

  • Added runWithGrace and runCallback functions to allow task callbacks a configurable grace period to exit after context deadline, improving reliability when handling long-running or blocking tasks.
  • Added tests to verify that tasks return errors if they exceed their TTL and that callback errors are handled correctly during the grace period.

Partition and queue management:

  • Ensured at least one task partition exists before any task inserts, preventing failures during queue initialization.
  • Added a test to verify that expired running tasks are reclaimed and do not block queue progress, using atomic counters and explicit partition management. [1] [2]

SQL schema updates:

  • Updated the SQL logic in objects.sql to exclude expired running tasks from the retained set and to allow selection of new tasks when previous running tasks have expired, enabling proper task reclamation. [1] [2]

@djthorpe djthorpe self-assigned this Jun 17, 2026
Copilot AI review requested due to automatic review settings June 17, 2026 15:21
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

Coverage for this change: 13.3%

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 pull request updates the pgqueue task execution/locking behavior to better handle tasks that overrun their TTL and to prevent initialization-time insert failures by ensuring task partitions exist.

Changes:

  • Updated queue_lock SQL to (a) stop counting expired running tasks toward concurrency and (b) allow selecting expired running tasks for reclamation.
  • Ensured at least one task partition is created during manager.New bootstrap.
  • Added/expanded tests covering TTL/grace behavior and reclaiming expired running tasks.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pgqueue/schema/objects.sql Adjusts queue_lock logic to exclude expired running tasks from retained concurrency counts and allow reclaim selection.
pgqueue/manager/manager.go Creates an initial task partition during manager bootstrap to avoid insert failures when no partitions exist.
pgqueue/manager/exec.go Adds grace-period wrapper (runWithGrace) around callbacks to return on context deadline/cancellation.
pgqueue/manager/queue_test.go Adds a regression test asserting queue progress continues when a running task expires.
pgqueue/manager/exec_test.go Adds unit tests validating runWithGrace behavior when callbacks block or exit during grace.

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

Comment thread pgqueue/manager/exec.go
Comment thread pgqueue/manager/queue_test.go Outdated
@djthorpe djthorpe merged commit bb3deec into main Jun 17, 2026
2 checks passed
@djthorpe djthorpe deleted the djt/0617/fail branch June 17, 2026 15:43
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