Repository navigation
refactor: behaviour-preserving simplification pass (2.1.x) - #95
Merged
Merged
Conversation
… backends The PostgreSQL and MySQL backends each carried a copy of the backend-independent parts of reading a job row and of a lifecycle transition. - queue/row.rs: the job column lists, status/result-storage/dependency-status decoding and the encryption column decoding (EncryptionRow), used by both JobRow::into_job implementations. - lifecycle.rs: a TransitionStore trait for the dialect-specific statements, and one generic transition_in_tx / after_terminal / apply_failure_policy / fail_job_dependencies plus manual_transition and finish_run, replacing the per-backend copies and the five manual-transition wrappers in each backend. - lifecycle.rs: one module-level dead_code allowance instead of 18 per-item cfg_attr lines. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dule, bind by reference - MySQL's retry_on_deadlock was a copy of retry_on_conflict (same attempts and backoff; its SQLSTATE 40001 check is the MySQL half of is_transaction_conflict). The claim path now uses retry_on_conflict. - The pub(crate) helpers in queue/mod.rs used only by the SQL backends move to queue/backend.rs (re-exported, so call sites are unchanged), with one module-level dead_code allowance replacing 26 per-item cfg_attr lines. - insert_jobs binds the job's fields by reference instead of cloning the payload, strings and encoded columns of every enqueued job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fetching - Config::resolve_database_url replaces fourteen copies of the --database-url / config fallback (same "Database URL is required" error). - with_queue! replaces the Postgres/MySQL matches whose arms made the same JobQueue call (27 sites, including archive.rs building JobQueue::new by hand). - fetch_rows! and IdText replace per-backend row loops whose arms differed only in how the id column decodes (job list, queue stats, monitor dashboard, audit log, backup/export job data). - batch export without payload drops the payload column from csv_fields instead of rebuilding the JobData and re-splitting the CSV row (same output). - status_name delegates to JobStatus::as_str. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Display - overview_handler re-implemented generate_overview_from_stats line for line; it now calls it. - archive handlers spelled out try_api! by hand. - Two handlers matched JobPriority to the names its Display impl already prints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- backend_tests! (five copies) and test_queue() (three) move to test_utils; the batch dequeue tests pass their multi-threaded test attribute. - scenario_tests! replaces 118 hand-written one-line wrappers (test_<backend>_x calls x(setup().await)) in eight files. Test names and module paths are unchanged, so the CI --skip mysql / mysql filters select the same tests (checked against the --list output). - wait_for_job (four copies), eventually (three) and idle_worker (two) are shared. The pool tests' eventually now polls every 25ms and checks once more at the deadline, like the worker config tests' copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ol task spawning - maintain_lease and maintain_held_leases share every_heartbeat (the interval, the zero-lease case and the never-completing tail); maintain_lease recomputed the interval held_renewal_interval already gives. - Acquired<T> serves the single-job and batch paths (AcquiredBatch and idle_wait_batch removed). - job_event builds the six JobEvents, and announce_retry is the retry hook and event shared by failed and timed-out runs. - The stale job reaper, encrypted job purge and result cleanup spawn through spawn_queue_task (spawn_periodic on the first worker's queue). - Lock reads use map/unwrap_or_default instead of if-let/else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ules worker.rs (5.8k lines) keeps Worker; worker/hooks.rs holds the job event hooks, worker/autoscale.rs the autoscaling configuration, metrics and decision, and worker/pool.rs WorkerPool with its supervisor and maintenance tasks. Each module carries its own unit tests. The public paths (hammerwork::worker:: WorkerPool, AutoscaleConfig, JobEventHooks, ...) are re-exported unchanged. Code is moved, not changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- calculate_job_level threaded an unused _current_level through its recursion. - JobQueue::pool is public, so its allow(dead_code) did nothing. - test_utils::skip_known_bug had no callers. - A comment in the web queue API called get_priority_stats "new". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 11, 2026
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.
A behaviour-preserving cleanup for a 2.1.x patch release. It removes duplication that built up across the parallel 2.x PRs and changes no public API. Each commit covers one area, so the PR reads best commit by commit (
git show --color-movedhelps with the moves).Net: −1,245 lines (+4,686 / −5,931 across 43 files; about 2,300 lines on each side are moves between files).
Queue backends (
src/queue): net −224queue/row.rs(new): the backend-independent parts of decoding ahammerwork_jobsrow, which bothJobRow::into_jobcopies now use:EncryptionRow). Each backend used to carry about 230 identical lines of this.lifecycle.rs:TransitionStoretrait holds the dialect-specific statements (lock job, write target, lock and refresh workflow, resolve and fail dependents, batch outcome).transition_in_tx,after_terminal,apply_failure_policyandfail_job_dependenciesare now one generic implementation instead of one per backend.manual_transitionandfinish_runreplace the five manual-transition wrappers in each backend.TIMESTAMP" filter is now the trait hookcan_schedule_at.retry_on_deadlockwas a copy ofretry_on_conflict, with the same five attempts and 5ms·n backoff. Its SQLSTATE 40001 check is the MySQL half ofis_transaction_conflict, so the claim path now usesretry_on_conflict.queue/backend.rs(new): thepub(crate)helpers that only the SQL backends use move out ofqueue/mod.rs. They are re-exported, so call sites are unchanged. One module-leveldead_codeallowance replaces 26 per-itemcfg_attrlines, andlifecycle.rsgets the same treatment, replacing 18.insert_jobsbinds job fields by reference instead of cloning the payload, strings and encoded columns of every enqueued job.fill_weighted_batchfrom fix: batch-mode pause, weighted batch claim loss, undecodable rows in the reaper and MySQL claims #93 stays shared, now inbackend.rs.Worker (
src/worker.rs): net +47, mostly module headers and importsHeartbeats:
maintain_leaseandmaintain_held_leasesshareevery_heartbeat, which owns the interval, the zero-lease case and the never-completing tail.Acquisition:
Acquired<T>serves both the single-job and batch paths, replacingAcquiredBatchandidle_wait_batch.Events:
job_eventbuilds the sixJobEvents, andannounce_retryis the retry hook plus event that failed and timed-out runs share.Pool maintenance: the reaper, the encrypted-job purge and the result cleanup spawn through
spawn_queue_task, a thin wrapper over the existingspawn_periodic. Archival keeps its own setup because it builds aJobArchiverfirst.Module split:
worker.rs(5.8k lines) is split into:worker/hooks.rsworker/autoscale.rsworker/pool.rs(WorkerPool, its supervisor and maintenance tasks)Each module carries its own unit tests.
Workerstays inworker.rs, andhammerwork::worker::*paths are re-exported unchanged. Code is moved, not changed.CLI (
cargo-hammerwork): net −308Config::resolve_database_urlreplaces 14 copies of the--database-url/config fallback. The error is the same: "Database URL is required".with_queue!replaces 27 Postgres/MySQL matches whose arms made the sameJobQueuecall. This includesarchive.rs, which builtJobQueue::newby hand.fetch_rows!plusIdTextreplace the per-backend row loops whose arms differed only in how the id column decodes. Sites: job list, queue stats, monitor dashboard, audit log, backup/export job data.csv_fieldsinstead of rebuilding theJobDataand re-splitting the CSV row. Output is identical, and the splitter stays as a test helper so its assertion remains.status_namedelegates toJobStatus::as_str.Web (
hammerwork-web): net −69overview_handlerwas a line-for-line copy ofgenerate_overview_from_statsand now calls it.try_api!; they now use the macro.JobPriority'sDisplay; they now use it.Tests: net −691
backend_tests!(five copies) andtest_queue()(three) move totest_utils.scenario_tests!replaces 118 one-line wrappers of the formtest_<backend>_x() { x(setup().await).await }across eight files.wait_for_job(four copies),eventually(three) andidle_worker(two) now live intest_utils.--skip mysql/mysqlfilters select the same tests. I checked the--listoutput against the pre-change run: 417 integration tests, none missing and none added.eventuallynow polls every 25ms and checks once more at the deadline, asworker_config_testsalready did. No assertion was removed.Dead code
calculate_job_level's unused_current_level.allow(dead_code)on the publicJobQueue::pool.test_utils::skip_known_bug, which had no callers.Behaviour notes for review
JobRow::into_joberror precedence: it now decodespii_fieldsbefore the encryption columns. A row that is invalid in both places reports thepii_fieldserror instead of the encryption one. Valid rows are unaffected, because the strict list decode already failed whenever the old lenient fallback could have differed.Verification
Run locally against PostgreSQL 16 and MySQL 8, the way
ci.ymlruns them:cargo test --workspace --all-features -- --include-ignored --skip mysqlcargo test --workspace --all-features -- --include-ignored mysql(both URLs on MySQL)cargo test -p hammerwork --doc--features postgres,mysql,test,encryption,tracing,streaming,kafkacargo fmt --all --checkcargo clippy --workspace --all-targets --all-features --locked -- -D warningsclippy -p hammerwork --lib --tests --no-default-featuresfor all 8 matrix entriescargo +1.91.1 check --workspace --all-features --all-targets --lockedcargo llvm-cov, both suites merged, CI ignore regex🤖 Generated with Claude Code