mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +10:00
feat: make jobs client type safe
This commit is contained in:
@ -3,12 +3,12 @@ import type { BaseJobProvider as JobClientProvider } from './base';
|
||||
import { LocalJobProvider } from './local';
|
||||
import { TriggerJobProvider } from './trigger';
|
||||
|
||||
export class JobClient {
|
||||
export class JobClient<T extends Array<JobDefinition> = []> {
|
||||
private static _instance: JobClient;
|
||||
|
||||
private _provider: JobClientProvider;
|
||||
|
||||
private constructor() {
|
||||
public constructor(definitions: T) {
|
||||
if (process.env.NEXT_PRIVATE_JOBS_PROVIDER === 'trigger') {
|
||||
this._provider = TriggerJobProvider.getInstance();
|
||||
|
||||
@ -16,23 +16,27 @@ export class JobClient {
|
||||
}
|
||||
|
||||
this._provider = LocalJobProvider.getInstance();
|
||||
|
||||
definitions.forEach((definition) => {
|
||||
this._provider.defineJob(definition);
|
||||
});
|
||||
}
|
||||
|
||||
public static getInstance() {
|
||||
if (!this._instance) {
|
||||
this._instance = new JobClient();
|
||||
}
|
||||
// public static getInstance() {
|
||||
// if (!this._instance) {
|
||||
// this._instance = new JobClient();
|
||||
// }
|
||||
|
||||
return this._instance;
|
||||
}
|
||||
// return this._instance;
|
||||
// }
|
||||
|
||||
public async triggerJob(options: TriggerJobOptions) {
|
||||
public async triggerJob(options: TriggerJobOptions<T>) {
|
||||
return this._provider.triggerJob(options);
|
||||
}
|
||||
|
||||
public defineJob<T>(job: JobDefinition<T>) {
|
||||
return this._provider.defineJob(job);
|
||||
}
|
||||
// public defineJob<N extends string, T>(job: JobDefinition<N, T>) {
|
||||
// return this._provider.defineJob(job);
|
||||
// }
|
||||
|
||||
public getApiHandler() {
|
||||
return this._provider.getApiHandler();
|
||||
|
||||
Reference in New Issue
Block a user