mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +00:00
feat(server): take a database lease before a cron tick runs
waitForCompletion only kept a tick from overlapping itself inside one process. Two processes on the same database (a rolling update's overlap, a second replica, a dev container pointed at the same file) both ran every job: two auto-backups, double syncs and retention sweeps, and reminder runs racing each other. A new migration adds scheduler_leases, and CronRegistrarService now runs every registered tick through SchedulerLeasesRepository.acquire: one conditional UPDATE moves the job's row to this process when it is free (no holder, a lapsed holder, or this process already), so exactly one process wins. A running tick renews its lease every 20 seconds, a crashed holder frees the job after a minute, and a finished tick keeps the lease for 30 seconds so a peer whose timer fires late does not run the same tick again. The per-row reminder claims stay as they are; jobs need no change of their own.
This commit is contained in:
@@ -14,7 +14,7 @@ import { createTestOrm, type TestOrm } from '../../helpers/test-orm';
|
||||
* `scripts/generate-entities.ts`'s `RULE1d_fixNaNNumericDefaults` and
|
||||
* `tests/unit/db/generate-entities.test.ts`'s `RULE1D-*` fixture tests for
|
||||
* the mechanism). This file pins the OUTPUT of that rule against the real,
|
||||
* committed entities — every one of the 130, not a sample — and reproduces
|
||||
* committed entities — every one of the 131, not a sample — and reproduces
|
||||
* the reviewer's own insert probe so a future regenerate/hand-edit that
|
||||
* reintroduces a `NaN` initialiser fails loudly here, not silently at a
|
||||
* caller's first `em.create()`.
|
||||
@@ -22,10 +22,11 @@ import { createTestOrm, type TestOrm } from '../../helpers/test-orm';
|
||||
/** NOT NULL scalars with neither a column default nor a class-field initialiser (legitimate: the caller must supply them). */
|
||||
// 424 + push_subscriptions (legacy step 245): id, user_id, endpoint, p256dh, auth, vapid_public_key.
|
||||
// + Tours: tour_types label_key, icon, color; tours.tour_type; tour_waypoints id, place_id, lat, lng, role, sequence.
|
||||
const KNOWN_UNINITIALISED_NOT_NULL_SCALARS = 440;
|
||||
// + scheduler_leases: name, owner, expires_at (the scheduler always writes all three).
|
||||
const KNOWN_UNINITIALISED_NOT_NULL_SCALARS = 443;
|
||||
|
||||
describe('entity class fields never carry a NaN initialiser (task-4-review-shape.md, Important 1)', () => {
|
||||
it('CLASSFIELD-001: new X() has no own property whose value is NaN, across all 130 entities', () => {
|
||||
it('CLASSFIELD-001: new X() has no own property whose value is NaN, across all 131 entities', () => {
|
||||
const failures: string[] = [];
|
||||
for (const schema of ALL_ENTITIES) {
|
||||
const Ctor = schema.class as new () => Record<string, unknown>;
|
||||
|
||||
Reference in New Issue
Block a user