mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 07:43:16 +10:00
30 lines
928 B
TypeScript
30 lines
928 B
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 { 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())
|
|
.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();
|
|
}
|
|
}
|