import { DataSource } from 'typeorm'; import { JobHandler, JobTimeoutHandler } from '../job'; import { ILogger } from '../logger'; /** * Job handlers registered for job types. * * Example: * ``` * { retry: { handle: (job) => { return { success: true, data: {}, } }, handleTimeout: (job) => { // define custom on timeout logic here // such as rescheduling // the decision of what to do is the job creator's // because not all jobs should be rescheduled(retried) // as they might not be idempotent. return }, }, } * ``` */ type JobHandlers = Record; declare class Config { static verifyConfig(config: Config): void; static getInstance(config: Config): Config; /** * DataSource object connected to Postgres */ postgresDataSource: DataSource; /** * Function that creates a logger. If passed, scheduler will log relevant messages. * If not passed, scheduler will not log anything. * @returns A new logger matching the `ILogger` interface. */ getLogger?: () => ILogger; /** * Cron expression that determines the frequency of running cleanup job to fail jobs stuck in running. * By default it is run every minute (`'* * * * *'`) */ cleanupFrequency?: string; /** * Amount of time spent in `running` state after the job is judged to be stuck * due to an event such as server instance crash or simply hanging because of its own logic. * * In case of a Scheduler, such a job is then cleaned up by marking it as failed and optionally * scheduling a new job for the job handler's `handleTimeout` method if it is defined. Default is 30 minutes. * * In case of a Processor with a `runSlowJobsInBackground` set to `true`, the job is left running up to this timeout * but then removed from the running jobs set, and will not be waited for when stopping the processor. * * If you configure both Schedulers and Processors, you should try to make this the same amount of time for both. */ jobRunningTimeoutMs?: number; /** * Job handlers to register to handle executions and timeouts of jobs */ jobHandlers?: JobHandlers; /** * Limit of number of jobs to cleanup in a single run of the cleanup job. Default is 500. */ cleanupJobLimit?: number; /** * Number of jobs to fetch in a single batch when processing jobs. Default is 10. */ jobBatchSize?: number; /** * Whether to run slow jobs in the background without blocking getting a new batch of jobs. Default is `true`. */ runSlowJobsInBackground?: boolean; /** * Limit of jobs to leave running in background in case `runSlowJobsInBackground` is set to `true`. Default is 20. */ backgroundJobLimit?: number; } export { Config, JobHandlers };