mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-24 16:03:02 +00:00
refactor(scheduling): take a cron lease in one conditional upsert
acquire() made sure a row existed and then raced on a conditional UPDATE, two statements the registrar wrapped in a transaction of its own. lint:tx cannot follow a repository reached through a local variable, so it reported the method. One INSERT ... ON CONFLICT DO UPDATE ... WHERE now takes a free lease, renews the holder's and leaves anyone else's alone, atomically on SQLite and on Postgres, and needs no transaction.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { createSnapshotTestDb } from '../../../helpers/db-mock';
|
||||
import { createTestOrm, type TestOrm } from '../../../helpers/test-orm';
|
||||
import { deleteRows } from '../../../helpers/factories/rows';
|
||||
import { SchedulerLeases } from '../../../../src/db/entities/SchedulerLeases.entity';
|
||||
import type { SchedulerLeasesRepository } from '../../../../src/db/repositories/SchedulerLeases.repository';
|
||||
|
||||
@@ -17,8 +18,8 @@ beforeAll(async () => {
|
||||
t = await createTestOrm(testDb);
|
||||
leases = t.repo(SchedulerLeases);
|
||||
});
|
||||
beforeEach(() => {
|
||||
testDb.prepare('DELETE FROM scheduler_leases').run();
|
||||
beforeEach(async () => {
|
||||
await deleteRows(t, SchedulerLeases);
|
||||
t.clear();
|
||||
});
|
||||
afterAll(async () => {
|
||||
|
||||
Reference in New Issue
Block a user