import { type mongodb, type ModuleInput } from '@unchainedshop/mongodb'; import { type DateFilterInput, type SortOption } from '@unchainedshop/utils'; import { type Work, WorkStatus } from '../db/WorkQueueCollection.ts'; export declare const DIRECTOR_MARKED_FAILED_ERROR = "DIRECTOR_MARKED_FAILED"; export type WorkData = Pick, 'input' | 'originalWorkId' | 'priority' | 'retries' | 'timeout' | 'worker' | 'scheduleId'> & Pick; export interface WorkResult { success: boolean; result?: Result; error?: any; } export declare const WorkerEventTypes: { readonly ADDED: "WORK_ADDED"; readonly ALLOCATED: "WORK_ALLOCATED"; readonly FINISHED: "WORK_FINISHED"; readonly DELETED: "WORK_DELETED"; readonly RESCHEDULED: "WORK_RESCHEDULED"; }; export type WorkerEventTypes = (typeof WorkerEventTypes)[keyof typeof WorkerEventTypes]; export interface WorkerSettingsOptions { blacklistedVariables?: string[]; } export interface WorkerReport { type: string; newCount: number; errorCount: number; successCount: number; startCount: number; deleteCount: number; } export interface WorkQueueQuery { created?: { end?: Date; start?: Date; }; types?: string[]; status?: WorkStatus[]; queryString?: string; scheduled?: { end?: Date; start?: Date; }; } export declare const buildQuerySelector: ({ created, scheduled, types, status, workId, queryString, ...rest }: mongodb.Filter & { created?: { end?: Date; start?: Date; }; scheduled?: { end?: Date; start?: Date; }; status?: WorkStatus[]; workId?: string; queryString?: string; types?: string[]; }) => { [x: string]: any; error?: any; timeout?: mongodb.Condition; originalWorkId?: mongodb.Condition; worker?: mongodb.Condition; input?: mongodb.Condition> | undefined; type?: mongodb.Condition | undefined; started?: mongodb.Condition; finished?: mongodb.Condition; priority?: mongodb.Condition | undefined; retries?: mongodb.Condition | undefined; scheduleId?: mongodb.Condition; result?: any; success?: mongodb.Condition; autoscheduled?: mongodb.Condition; updated?: mongodb.Condition; deleted?: mongodb.Condition; _id?: mongodb.Condition | undefined; $and?: mongodb.Filter>[] | undefined; $nor?: mongodb.Filter>[] | undefined; $or?: mongodb.Filter>[] | undefined; $text?: { $search: string; $language?: string; $caseSensitive?: boolean; $diacriticSensitive?: boolean; }; $where?: string | ((this: mongodb.WithId) => boolean) | undefined; $comment?: string | mongodb.BSON.Document; created?: mongodb.Condition | undefined; scheduled?: mongodb.Condition | undefined; }; export declare const configureWorkerModule: ({ db, options }: ModuleInput) => Promise<{ workerId: string; activeWorkTypes: () => Promise; findWork: (params: { workId: string; } | { originalWorkId: string; }) => Promise | null>; findWorkQueue: ({ limit, skip, sort, ...selectorOptions }: WorkQueueQuery & { sort?: SortOption[]; limit?: number; skip?: number; }) => Promise; count: (query: WorkQueueQuery) => Promise; allocationMap: () => Promise>; workExists: ({ workId, originalWorkId, }: { workId?: string; originalWorkId?: string; }) => Promise; status: (work: Work) => WorkStatus; addWork({ type, input, priority, scheduled, originalWorkId, worker, retries, }: Pick & Pick, "scheduled" | "priority" | "input" | "retries">): Promise; addWorkIfNotExists(workData: Pick & Pick, "scheduled" | "priority" | "input" | "retries">, existenceCheck: (work: Work) => boolean): Promise; rescheduleWork: (currentWork: Work, scheduled: Date) => Promise | null>; allocateWork: ({ types, worker, }: { types: string[]; worker: string; }) => Promise | null>; ensureNoWork: ({ type, priority, scheduleId, }: { priority: number; type: string; scheduleId: string; }) => Promise; ensureOneWork: ({ type, input, priority, scheduled, timeout, originalWorkId, retries, scheduleId, }: WorkData) => Promise | null>; finishWork: (workId: string, { error, finished, result, started, success, worker, }: WorkResult & { finished?: Date; started?: Date; worker?: string; }) => Promise | null>; deleteWork: (workId: string) => Promise | null>; markOldWorkAsFailed: ({ types, worker, referenceDate, }: { types: string[]; worker: string; referenceDate: Date; }) => Promise; getReport: ({ types, dateRange, }: { types?: string[]; dateRange?: DateFilterInput; }) => Promise; }>; export type WorkerModule = Awaited>;