mirror of
https://github.com/Unleash/unleash.git
synced 2025-03-09 00:18:26 +01:00
## About the changes
This PR provides a service that allows a scheduled function to run in a
single instance. It's currently not in use but tests show how to wrap a
function to make it single-instance:
65b7080e05/src/lib/features/scheduler/job-service.test.ts (L26-L32)
The key `'test'` is used to identify the group and most likely should
have the same name as the scheduled job.
---------
Co-authored-by: Christopher Kolstad <chriswk@getunleash.io>
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { createTestConfig } from '../../../test/config/test-config';
|
|
import { JobStore } from './job-store';
|
|
import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init';
|
|
|
|
let db: ITestDb;
|
|
const config = createTestConfig();
|
|
beforeAll(async () => {
|
|
db = await dbInit('job_store_serial', config.getLogger);
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await db.destroy();
|
|
});
|
|
|
|
test('cannot acquireBucket twice', async () => {
|
|
const store = new JobStore(db.rawDatabase, config);
|
|
// note: this might be flaky if the test runs exactly at 59 minutes and 59 seconds of an hour and 999 milliseconds but should be unlikely
|
|
const bucket = await store.acquireBucket('test', 60);
|
|
expect(bucket).toBeDefined();
|
|
const bucket2 = await store.acquireBucket('test', 60);
|
|
expect(bucket2).toBeUndefined();
|
|
});
|
|
|
|
test('Can acquire bucket for two different key names within the same period', async () => {
|
|
const store = new JobStore(db.rawDatabase, config);
|
|
const firstBucket = await store.acquireBucket('first', 60);
|
|
const secondBucket = await store.acquireBucket('second', 60);
|
|
expect(firstBucket).toBeDefined();
|
|
expect(secondBucket).toBeDefined();
|
|
});
|