Repository navigation
perf(jobworker): cache claim prepared statement and add claim index - #8
Merged
Merged
Conversation
Optimize the StartNextJobOrNil claim path: claim and start the next job in a single CTE prepared statement (cached, re-prepared only on Register/Unregister) with registered job types inlined as SQL literals, backed by a new partial claim index worker_job_claim_idx. Claim timestamps now use the database clock (now()) for clock-skew immunity. RegisteredJobTypes() returns a cached, sorted, shared slice plus a generation counter so consumers rebuild only when it changes. Add unit tests (job/jobbundle/jobtype/status, registerFunc, context) and DB integration tests covering all previously-untested jobworkerdb query, delete, and closed-service methods. run-tests.sh now runs ./... and the Go toolchain is bumped to 1.26. BREAKING CHANGE: jobworker.RegisteredJobTypes() now returns (jobTypes []string, generation uint64) instead of notnull.StringArray; the returned slice is shared and must not be mutated.
Pin revive and gosec in a separate tools/go.mod and run go vet, revive (revive.toml), and gosec before the tests in run-tests.sh. Fix the reported findings: - service.go: omit the inferred Service type from the defaultService var - jobworker: rename a clear closure that shadowed the builtin - jobworker: use errs.New instead of fmt.Errorf for a non-formatted message In tests, call t.Context() directly instead of aliasing it to ctx, and have test helpers derive t.Context() internally rather than taking a context parameter (also resolves revive's context-as-argument).
Bump VERSION to v0.7.0 (minor) for the breaking RegisteredJobTypes signature change. Sync README, CLAUDE.md, and CHANGELOG with what shipped: the startup-only registration panic, HeartbeatInterval immutability, the single-active-service caveat, the static-analysis test step (go vet/revive/gosec, -s flag, go test ./...), the Go 1.26.0 toolchain bump, and a precision fix to the worker_job_claim_idx ordering claim (per-type merge, not a global no-sort scan). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Optimizes the hot
StartNextJobOrNilclaim path: it claims and starts the next job in a single cached CTE prepared statement (re-prepared only on Register/Unregister) with registered job types inlined as SQL literals, backed by a new partialworker_job_claim_idxindex, and stampsstarted_at/updated_at/worker_alive_atfrom the database clock for clock-skew immunity. BREAKING:jobworker.RegisteredJobTypes()now returns(jobTypes []string, generation uint64)— a cached, sorted, shared slice that must not be mutated — instead ofnotnull.StringArray. Registration (Register/RegisterFunc/RegisterFuncForJobType/Unregister) is now startup-only and panics if called while worker threads are running. Adds unit tests (job/jobbundle/jobtype/status, reflection-basedregisterFunc, context helpers) plus DB integration tests covering every previously-untestedjobworkerdbquery, delete, and closed-service method. Also adds revive/gosec lint tooling (pinned intools/go.mod, run byrun-tests.shbefore tests), makes the test run cover./..., bumps the Go toolchain to 1.26 (go.mod + CI), and updates thego-sqldb/go-errs/golog/go-typesdependencies.Releases as v0.7.0 (minor bump from v0.6.0, for the breaking
RegisteredJobTypes()change). Existing databases must add the new claim index out-of-band — see the migration inCHANGELOG.md.Documentation
HeartbeatIntervalimmutability constraint (set beforeStartThreads), the optionalworker_job_claim_idxmigration, and the refreshed test workflow (static analysis viago vet/revive/gosec,-sto skip,go test ./...).HeartbeatIntervalimmutability.v0.7.0entry: the new claim index, the single-CTE cached claim statement, database-clock timestamps, the breakingRegisteredJobTypes()change, the registration panic, the Go 1.26 toolchain bump, dependency updates, and the index migration SQL.No outstanding documentation debt: every new public surface (
worker_job_claim_idx, theRegisteredJobTypes()change, the registration panic,HeartbeatIntervalimmutability, the single-active-service caveat) is covered in the docs above and in godoc.