-
Notifications
You must be signed in to change notification settings - Fork 102
Feature: add support for jobs to run sequentially #2461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
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 adds support for sequential job execution in the Jobs plugin through a new sequentialKey parameter. Jobs sharing the same sequential key will execute one at a time in creation order, with subsequent jobs waiting until the active job completes.
Changes:
- Added
sequentialKeycolumn to the jobs table - Jobs with an active sequential key are created in WAITING state instead of QUEUED
- When jobs complete via FinishJob, FailJob, or DeleteJob, the next WAITING job with the same key is promoted to QUEUED
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/Jobs.cpp | Added sequentialKey column to schema, logic to set jobs to WAITING when sequential key exists, and promotion logic in FinishJob/FailJob/DeleteJob |
| plugins/Jobs.md | Documented the sequentialKey parameter and its limitations with repeat and parentJobID |
| test/tests/jobs/CreateJobTest.cpp | Added comprehensive tests for sequential job creation and ordering |
| test/tests/jobs/FailJobTest.cpp | Added test verifying FailJob promotes waiting jobs |
| test/tests/jobs/DeleteJobTest.cpp | Added test verifying DeleteJob promotes waiting jobs |
| test/clustertest/tests/FinishJobTest.cpp | Added test verifying FinishJob promotes waiting jobs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // If sequentialKey is set, check if there are other pending jobs with the same key. | ||
| // If so, this job should wait for them to complete before running by setting the initial state to WAITING. | ||
| const string& safeSequentialKey = SContains(job, "sequentialKey") ? SQ(job["sequentialKey"]) : SQ(""); | ||
| if (safeSequentialKey != SQ("")) { | ||
| SQResult result; | ||
| if (!db.read("SELECT 1 FROM jobs " | ||
| "WHERE sequentialKey=" + safeSequentialKey + " " | ||
| "AND state IN ('QUEUED', 'RUNQUEUED', 'RUNNING', 'WAITING') " | ||
| "LIMIT 1;", result)) { | ||
| STHROW("502 Select failed"); | ||
| } | ||
| if (!result.empty()) { | ||
| initialState = "WAITING"; | ||
| } | ||
| } |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing validation to prevent unsupported combinations of sequentialKey with repeat or parentJobID. The PR description states these are unsupported because jobs with repeat or parentJobID don't get deleted on completion, preventing WAITING jobs from being promoted. However, there's no validation to prevent users from creating jobs with these combinations, which would lead to unexpected behavior where WAITING jobs never get promoted to QUEUED.
| "parentJobID INTEGER NOT NULL DEFAULT 0, " | ||
| "retryAfter TEXT NOT NULL DEFAULT \"\")", | ||
| "retryAfter TEXT NOT NULL DEFAULT \"\", " | ||
| "sequentialKey TEXT NOT NULL DEFAULT \"\")", |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing database index for sequentialKey column. The queries at lines 617-620, 1224-1230, 1330-1336, and 1383-1389 filter by sequentialKey without an index, which will cause performance issues as the jobs table grows. An index should be added similar to other indexed columns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need an index? I thinkk let's add it when it becomes a problem
| // If sequentialKey is set, check if there are other pending jobs with the same key. | ||
| // If so, this job should wait for them to complete before running by setting the initial state to WAITING. | ||
| const string& safeSequentialKey = SContains(job, "sequentialKey") ? SQ(job["sequentialKey"]) : SQ(""); | ||
| if (safeSequentialKey != SQ("")) { | ||
| SQResult result; | ||
| if (!db.read("SELECT 1 FROM jobs " | ||
| "WHERE sequentialKey=" + safeSequentialKey + " " | ||
| "AND state IN ('QUEUED', 'RUNQUEUED', 'RUNNING', 'WAITING') " | ||
| "LIMIT 1;", result)) { | ||
| STHROW("502 Select failed"); | ||
| } | ||
| if (!result.empty()) { | ||
| initialState = "WAITING"; | ||
| } | ||
| } |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sequentialKey logic can override the parentJobID state logic, which could break parent-child job semantics. When both parentJobID and sequentialKey are set (an unsupported combination per the PR description), a child job that should be PAUSED (lines 605-610) can be set to WAITING (line 624), preventing it from running when the parent finishes. This is another reason why the combination should be explicitly validated and rejected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2daa99573f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| "data TEXT NOT NULL, " | ||
| "priority INTEGER NOT NULL DEFAULT " + SToStr(JOBS_DEFAULT_PRIORITY) + ", " | ||
| "parentJobID INTEGER NOT NULL DEFAULT 0, " | ||
| "retryAfter TEXT NOT NULL DEFAULT \"\")", | ||
| "retryAfter TEXT NOT NULL DEFAULT \"\", " | ||
| "sequentialKey TEXT NOT NULL DEFAULT \"\")", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add migration for sequentialKey column
This change only updates the CREATE TABLE jobs SQL. verifyTable doesn’t alter existing tables, so an upgraded deployment with a pre-existing jobs table will still be missing sequentialKey, and subsequent statements like INSERT INTO jobs (..., sequentialKey) or the new SELECT ... sequentialKey will fail with “no such column,” breaking job creation/finish on upgrade. Please add an explicit schema migration (e.g., addColumn) or a guarded alter step for existing databases.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't do this is code right? have to manually run Alter table before deploying this code
Details
For Jobs plugin, added a new
sequentialKeyparam. If multiple jobs have the samesequentialKey, then they will run one at a time, in the order they were created in.sequentialKeycolumn to jobs tableWAITINGstate instead ofQUEUEDWAITINGjob with the same key is promoted toQUEUEDUnsupported stuff
I couldn't think of a usecase / requirement at the moment for these
repeatwith sequentialKey - A repeating job never gets deleted, so WAITING jobs won't be promoted.Fixed Issues
See - https://expensify.slack.com/archives/C086VHWPPUM/p1768336706994209?thread_ts=1768271555.676269&cid=C086VHWPPUM
Part of https://github.com/Expensify/Expensify/issues/568339
Tests
Unit tests added that verify
Internal Testing Reminder: when changing bedrock, please compile auth against your new changes