Djt/0617/dies at fix#58
Merged
Merged
Conversation
|
Coverage for this change: 12.4% |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes how dies_at/task deadlines are represented and managed in pgqueue, shifting from “deadline set at insert time” to “deadline set when a worker locks the task”, and adjusts manager scheduling behavior accordingly.
Changes:
- Make
dies_atnullable in both the Go schema (*time.Time) and the SQL schema, and update logic to only treat tasks as expired when a deadline exists. - Move
dies_atassignment toqueue_lock(set on lock), and cleardies_atonqueue_unlock/queue_fail. - Improve queue draining behavior in the manager run loop (cap per-round pickups and trigger immediate rescheduling when a slot frees up).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
pgqueue/schema/task.go |
Changes Task.DiesAt to *time.Time to allow “unset until locked” semantics. |
pgqueue/schema/objects.sql |
Makes dies_at nullable and moves deadline computation to lock/unlock/fail functions; updates expiration logic. |
pgqueue/manager/task_test.go |
Updates task creation expectation to DiesAt == nil (deadline set on lock). |
pgqueue/manager/run.go |
Caps queue pickup per round and resets queue polling when a task completes. |
pgqueue/manager/exec.go |
Updates deadline handling to match nullable DiesAt. |
pgqueue/manager/exec_test.go |
Updates tests for pointer-based DiesAt. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "initial_retries" INTEGER NOT NULL CHECK ("initial_retries" >= 0), | ||
| PRIMARY KEY ("id"), | ||
| FOREIGN KEY ("queue") REFERENCES ${"schema"}."queue" ("queue") ON DELETE CASCADE | ||
| ) PARTITION BY RANGE (id); |
| "started_at" TIMESTAMPTZ, | ||
| "finished_at" TIMESTAMPTZ, | ||
| "dies_at" TIMESTAMPTZ NOT NULL, | ||
| "dies_at" TIMESTAMPTZ, |
Comment on lines
+180
to
182
| // A slot just freed up — immediately try to pick up another task. | ||
| queueTimer.Reset(0) | ||
| continue |
Comment on lines
167
to
+168
| // Run the task function with the provided payload and deadline | ||
| child, cancel := context.WithDeadline(ctx, task.DiesAt.UTC()) | ||
| child, cancel := context.WithDeadline(ctx, (*task.DiesAt).UTC()) |
Comment on lines
43
to
46
| StartedAt *time.Time `json:"started_at,omitempty"` | ||
| FinishedAt *time.Time `json:"finished_at,omitempty"` | ||
| DiesAt time.Time `json:"dies_at,omitempty"` | ||
| DiesAt *time.Time `json:"dies_at,omitempty"` | ||
| Retries *uint64 `json:"retries,omitempty"` |
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.
Fixed debugging messages