/**
 * This file is part of the NocoBase (R) project.
 * Copyright (c) 2020-2024 NocoBase Co., Ltd.
 * Authors: NocoBase Team.
 *
 * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
 * For more information, please refer to: https://www.nocobase.com/agreement.
 */
import { Transactionable } from 'sequelize';
import type { QueueEventOptions } from '@nocobase/server';
import Processor, { ProcessorRerunOptions } from './Processor';
import type { WorkflowModel } from './types';
import type PluginWorkflowServer from './Plugin';
type ID = number | string;
type WorkflowQueueTask = {
    executionId: ID;
    jobId?: never;
    rerun?: never;
} | {
    executionId: ID;
    jobId: ID;
    rerun?: never;
} | {
    executionId: ID;
    jobId?: never;
    rerun: ProcessorRerunOptions;
};
export type EventOptions = {
    eventKey?: string;
    context?: any;
    deferred?: boolean;
    manually?: boolean;
    force?: boolean;
    stack?: Array<number | string>;
    parentExecutionId?: number | string;
    onTriggerFail?: (workflow: WorkflowModel, context: object, options: EventOptions, error?: unknown) => void | Promise<void>;
    [key: string]: any;
} & Transactionable;
export default class Dispatcher {
    private readonly plugin;
    private ready;
    private executing;
    private recovering;
    private saving;
    private events;
    private eventsCount;
    get idle(): boolean;
    constructor(plugin: PluginWorkflowServer);
    readonly onQueueTask: QueueEventOptions['process'];
    setReady(ready: boolean): void;
    getEventsCount(): number;
    trigger(workflow: WorkflowModel, context: object, options?: EventOptions): void | Promise<Processor | null | void>;
    private saveEvent;
    beforeStop(): Promise<void>;
    recover(options?: {
        gracePeriod?: number;
    }): Promise<void>;
    private recoverQueueTasks;
    enqueue(task: WorkflowQueueTask): Promise<void>;
    private loadJob;
    private findQueueingExecutions;
    private resolveTask;
    private triggerSync;
    private validateEvent;
    private handleTriggerFail;
    private createExecution;
    private prepare;
    private acquireExecution;
    private acquireWithRetry;
    private enter;
    private isConcurrentAcquireError;
    private process;
}
export {};
