mirror of
https://github.com/documenso/documenso.git
synced 2026-07-10 21:15:15 +10:00
ad559f72dd
Add a new BullMQ/Redis-backed job provider as an alternative to the existing Inngest and Local providers. Includes Bull Board UI for job monitoring at /api/jobs/board (admin-only in production, open in dev).
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { match } from 'ts-pattern';
|
|
|
|
import { env } from '../../utils/env';
|
|
import type { JobDefinition, TriggerJobOptions } from './_internal/job';
|
|
import type { BaseJobProvider as JobClientProvider } from './base';
|
|
import { BullMQJobProvider } from './bullmq';
|
|
import { InngestJobProvider } from './inngest';
|
|
import { LocalJobProvider } from './local';
|
|
|
|
export class JobClient<T extends ReadonlyArray<JobDefinition> = []> {
|
|
private _provider: JobClientProvider;
|
|
|
|
public constructor(definitions: T) {
|
|
this._provider = match(env('NEXT_PRIVATE_JOBS_PROVIDER'))
|
|
.with('inngest', () => InngestJobProvider.getInstance())
|
|
.with('bullmq', () => BullMQJobProvider.getInstance())
|
|
.otherwise(() => LocalJobProvider.getInstance());
|
|
|
|
definitions.forEach((definition) => {
|
|
this._provider.defineJob(definition);
|
|
});
|
|
}
|
|
|
|
public async triggerJob(options: TriggerJobOptions<T>) {
|
|
return this._provider.triggerJob(options);
|
|
}
|
|
|
|
public getApiHandler() {
|
|
return this._provider.getApiHandler();
|
|
}
|
|
|
|
/**
|
|
* Start the cron scheduler for any registered cron jobs.
|
|
*
|
|
* Call this once at application startup after the instance is ready to
|
|
* process requests. No-op for providers that handle cron externally
|
|
* (e.g. Inngest).
|
|
*/
|
|
public startCron() {
|
|
this._provider.startCron();
|
|
}
|
|
}
|