Repository navigation
fix: batch-mode FailFast, start times and token refunds; live Running->Pending updates; CLI, web and test follow-ups (#94) - #96
Merged
Conversation
…n refund for held batch jobs A batch-mode worker now checks, at most once per poll interval together with the pause check, whether the batch of a held job has failed; held jobs of a failed fail-fast batch are failed like its Pending jobs instead of run (or released on pause/shutdown). Held jobs that waited record their actual start through the new defaulted DatabaseQueue::start_claimed_run, so their wait is not counted as processing time. A held job skipped because its lease was lost refunds its rate limit token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ates Retries, reaper requeues and batch releases change none of the timestamps recent_job_changes reads, so live-update clients never saw them. Without a schema change there is no timestamp to query, so the poller now tracks the running jobs (JobHistory::running_jobs) and reads the state of the ones that stopped running unseen (JobHistory::job_states), reporting them at the poll that observed the change. Both trait methods have defaults, so the change is non-breaking. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…icons, webhook renames - backup create/restore and migration status connect with connect_with_config, so connect_timeout_secs applies. - maintenance vacuum reports the rows the deletes removed. - maintenance dead-jobs says it selects jobs that started more than N hours ago. - monitor's status icons cover Retrying and TimedOut. - webhook update --name rejects a name another webhook already has. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-run counts - uptime_seconds never goes negative, and callers convert without wrapping. - The job list treats sort_order "asc" case-insensitively (SortParams::is_ascending). - An archive dry run reports the number of jobs a real run would archive (JobHistory::count_archivable) instead of zeroed statistics. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… isolate VAULT_TOKEN - batch_tests checks that every job of a large batch comes back once, in creation order, instead of computing an index it never compared. - test_batch_statistics_tracking asserts the worker's batch statistics. - result_storage_tests, result_config_test, jobrow_query_tests and test_mysql_concurrent_dequeue delete their jobs through a drop guard (test_utils::QueueCleanup), so they clean up even when they fail; tests that shared the "test_queue" name now use unique queues. - The VAULT_TOKEN test re-runs itself in a child process without the variable instead of changing the environment of a process whose other tests run in parallel, and checks the error names VAULT_TOKEN. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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.
Closes #94
Fixes the batch-mode and live-update follow-ups in the issue body and the CLI, web and test items in the comment. Everything is non-breaking for 2.1.1. The new trait methods all have default implementations, so no item had to be moved to 3.0.
Batch mode (
src/worker.rs,src/queue/*)run_batch_until_donealready checks for a pause before starting a held job, at most once per poll interval. That same check now also reads the status of the batches the held jobs belong to (get_batch_status), one query per distinct batch, and remembers which ones have failed. A held job of a failed batch is failed the same way FailFast fails itsPendingjobs: statusFailed, no retry, errorBatch failed (fail-fast mode) before this claimed job started. Before failing it, the worker sends a heartbeat (heartbeat_job) to confirm it still holds the run. It does not release the job, because a released job would bePendingin a failed batch and would run later. On a pause or shutdown, held jobs of a failed batch are failed instead of released.DatabaseQueue::start_claimed_run(&mut Job, lease)setsstarted_atto the current database time and renews the lease, guarded by the run. It also updates the in-memory run, becausestarted_atis part of what identifies a run. PostgreSQL usesRETURNING. MySQL readsUTC_TIMESTAMP(6)first and writes that value.TestQueueimplements it too. The default implementation only sends a heartbeat. Held jobs call it when they start after the first fill, and it replaces the old "renew then run" heartbeat. Jobs that start straight after the claim keep the claim time and skip the extra write.Live updates (
hammerwork-web)recent_job_changesfilters on timestamps, and aRunningtoPendingtransition (a retry, a reaper requeue, a batch release) changes none of them. Detecting it without state would need a new column written on every transition, or a trigger. That is a schema change, and on MySQL a trigger can need extra privileges, which is too much for a patch release. Instead,LiveUpdateskeeps track of the jobs it has seen running:JobHistory::running_jobs(limit)returns the jobs currentlyRunning. The tracked set is these plus anyRunningrows in the change feed.JobHistory::job_states(ids)(at mostmax_jobsids per poll). If it is no longerRunning, aJobUpdateis pushed, stamped with the time of the poll that saw the change. If it is still running, it only fell out of the window and stays tracked.Both methods have defaults (
job_statesfalls back toget_job). Therecent_job_changesdocs now say this.CLI (
cargo-hammerwork)backup create/restoreandmigration statusconnect withconnect_with_config, soconnect_timeout_secsapplies.maintenance vacuumreports the row counts theDELETEs returned, not the counts taken before them.maintenance dead-jobstext and--stale-hourshelp say what is filtered:Runningjobs that started more than N hours ago. README updated.monitor's status icons coverRetryingandTimedOut, and tolerate JSON-quoted status values.webhook update --namerefuses a name another webhook already has. Keeping its own name is still allowed.Web
SystemState::uptime_secondsis clamped at 0, and callers convert withu64::try_from, so a clock going backwards no longer wraps the value.SortParams::is_ascendingmatchesasccase-insensitively. The job list andget_order_byboth use it.stats.jobs_archivedwith the count a real run would archive, from the new defaultedJobHistory::count_archivable. It uses the archiver's conditions and the policy'sbatch_sizecap.Tests
batch_tests(large batch): checks every index comes back exactly once and thatcreated_atnever decreases. It no longer computes an index and ignores it.test_batch_statistics_tracking: runs the worker through anArc, so its statistics stay readable after it stops, and asserts processed, completed, failed, batches, success rates and lower bounds on processing time.test_utils::QueueCleanupdrop guard deletes a queue's jobs on its own thread, runtime and connection. It works under any runtime and also runs when a test panics. It is used inresult_storage_tests,result_config_test,jobrow_query_testsandtest_mysql_concurrent_dequeue. Tests that shared thetest_queuename now use unique queues.VAULT_TOKEN: the test re-runs itself in a child process started withenv_remove("VAULT_TOKEN"), so the test process's environment is never changed and nounsafeis needed. It now asserts that the error namesVAULT_TOKEN.fail_fast_batch_fails_held_jobs,held_jobs_record_their_actual_startandlost_held_job_refunds_its_rate_limit_token. All three failed with the fixes reverted.clients_see_running_jobs_go_back_to_pending. It failed with the tracking turned off.start_claimed_runonTestQueue, the archivable-count SQL, sort order, uptime and status icons.started_atis at or after the previous job'scompleted_at), so it doesn't depend on elapsed time.Verification
--include-ignored --skip mysql): 1969 passed, 0 failed.--include-ignored mysql, both URLs on MySQL): 202 passed, 0 failed.cargo test -p hammerwork --doc: 186 passed.cargo fmt --all --checkandcargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.cargo clippy -p hammerwork --lib --tests --no-default-featuresfor every CI matrix entry: clean.🤖 Generated with Claude Code