import { Except } from 'type-fest'; import { EntityManager, FindOptionsOrder } from 'typeorm'; import { Config } from '../config'; import { JobEntity } from './job.entity'; import { JobStatus } from './types'; export type JobEntityUpdateData = Except, 'id' | 'created' | 'updated'>; export type JobEntityCreateData = Except, 'status' | 'resultData' | 'thread' | 'labels'> & { thread?: string; labels?: string[]; }; export declare class JobService { private readonly config; private readonly logger; private readonly repository; constructor(config: Config); /** * Creates a new job. If `thread` is not passed in `data`, a unique `thread` will be generated * @param data * @returns */ create(data: JobEntityCreateData, manager?: EntityManager): Promise; findById(id: string, manager?: EntityManager): Promise; /** * Deletes (only scheduled) jobs that match passed filters. * @param filters * @returns Number of affected jobs */ deleteScheduledJobs(filters: { method: string; thread?: string; labels?: string[]; }, manager?: EntityManager): Promise; /** * Changes schedule time (only if the job status is `scheduled`) * @param jobId * @returns Number of affected jobs */ reschedule(jobId: string, runAfter: Date, manager?: EntityManager): Promise; /** * Finds jobs that match passed filters. * @param filters * @param paging * @returns Jobs that match given filters */ find(filters: { method: string; thread?: string; labels?: string[]; status?: JobStatus[]; }, paging?: { order?: FindOptionsOrder; skip?: number; take?: number; }): Promise; update(id: string, data: Partial): Promise>; /** * Returns the next runnable job (by current time newer than `runAfter`), and marks it as `running`. * @param methods Applicable job methods. If `undefined`, all jobs apply. */ getNextJob(methods?: string[]): Promise; /** * Returns a maximum number of `limit` runnable (current time newer than `runAfter`) jobs in a batch, and marks them as `running`. * @param methods Applicable job methods. If `undefined`, all jobs apply. * @param limit Maximum number of jobs to return. */ getJobBatch(methods?: string[], limit?: number): Promise; /** * Finds jobs that have been in status `running` for longer than * `jobRunningTimeoutMs` and marks them as failed. */ failJobsStuckInRunning(manager?: EntityManager): Promise; /** * Returns information on the state of the job queue. * @returns Object containing information on the state of the job queue */ getQueuedJobsInfo(): Promise<{ queuedJobCount: number; }>; }