import type { TimeSpan } from 'src/NodeJS/types'; import { IJob } from './IJob'; import { IJobBase } from './IJobBase'; import { JobState } from './JobState'; /** A base repository to use for generic job management. */ export interface IJobRepository { /** * Adds a new job to the database. * * @param type The type of the job. * @param dueDate The date when the job should be executed. If not given current date is used. * @param parameters The parameters of the job. * @param cancellationToken A token to cancel the operation. * @returns The added job. */ addJobAsync(type: string, dueDate: Date | undefined, parameters?: TParams, cancellationToken?: AbortSignal): Promise>; /** * Adds the given amount to successful or failed items of the job to indicate progress. * * @param job The job. * @param items The amount of items to add. Defaults to 1. * @param failed If , amount is added to failed items instead of successful items. * @param cancellationToken A token to cancel the operation. * @returns A task indicating when the operation is complete. */ addProgressAsync(job: IJobBase, items?: number, failed?: boolean, cancellationToken?: AbortSignal): Promise; /** * Counts the jobs in the database optionally filtered by type or state. * * @param type The type of the job. * @param state The state of the job. * @param cancellationToken A token to cancel the operation. * @returns The amount of jobs in the database. */ countJobsAsync(type: string, state?: JobState, cancellationToken?: AbortSignal): Promise; /** * Deletes jobs from the database filtered by type, state, last updated date or a combination of these. * * @param type The type of the job. * @param state The state of the job. * @param lastUpdatedBefore The date until when the job was last updated. * @param cancellationToken A token to cancel the operation. * @returns The amount of jobs that were deleted. */ deleteJobsAsync(type: string, state?: JobState, lastUpdatedBefore?: Date | undefined, cancellationToken?: AbortSignal): Promise; /** * Checks if a job with the given conditions already exists and returns it if so. * * @param type The type of the job. * @param dueDate The date until when the job should be done. * @param parameters The parameters of the job. * @param includeStarted If job will also be found if state is , else only jobs that are are found. * @param cancellationToken A token to cancel the operation. * @returns The job if found or null if not. */ findExistingJobAsync(type: string, dueDate: Date | undefined, parameters?: TParams, includeStarted?: boolean, cancellationToken?: AbortSignal): Promise | undefined>; /** * Marks the job complete, sets the result and optionally adds a new job. * * @param job The job to complete. * @param addNextJobIn An optional timespan when the next job should be run. * @param cancellationToken A token to cancel the operation. * @returns A task indicating when the operation is completed. */ finishJobAsync(job: IJob, addNextJobIn: TimeSpan | undefined, cancellationToken?: AbortSignal): Promise; /** * Checks the jobs table for a job that is requested and the due date passed and the given type matches. If any * exist the one with the oldest due date is grabbed and updated. The state is set to Started. if no job with the * given conditions exist, null is returned. * * @param type The type of the job. * @param runner The unique name of the runner. Should contain the name, version number and a unique string. * @param cancellationToken A token to cancel the operation. * @returns The job with the oldest due date that matched the filter or null if no job matched. */ getAndStartFirstPendingJobAsync(type: string, runner: string, cancellationToken?: AbortSignal): Promise | undefined>; /** * Resets a job back to the requested state. * * @param job The job. * @param cancellationToken A token to cancel the operation. * @returns A task indicating when the operation is complete. */ resetJobAsync(job: IJob, cancellationToken?: AbortSignal): Promise; /** * Sets the amount of total items of the job. * * @param job The job. * @param total The amount of items to process in the scope of this job. * @param cancellationToken A token to cancel the operation. * @returns A task indicating when the operation is complete. */ setTotalItemsAsync(job: IJobBase, total: number, cancellationToken?: AbortSignal): Promise; }