@nocobase/plugin-workflow
Version:
A powerful BPM tool that provides foundational support for business automation, with the capability to extend unlimited triggers and nodes.
106 lines (105 loc) • 4.22 kB
TypeScript
/**
* 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 { Snowflake } from 'nodejs-snowflake';
import { Transactionable } from 'sequelize';
import { Plugin } from '@nocobase/server';
import { Registry } from '@nocobase/utils';
import { Logger } from '@nocobase/logger';
import Dispatcher, { EventOptions } from './Dispatcher';
import Processor from './Processor';
import ExecutionTimeoutManager from './ExecutionTimeoutManager';
import RunningExecutionRegistry from './RunningExecutionRegistry';
import { CustomFunction } from './functions';
import Trigger from './triggers';
import { InstructionInterface } from './instructions';
import type { ExecutionModel, WorkflowModel } from './types';
import type { Transaction } from '@nocobase/database';
type ID = number | string;
export declare const WORKER_JOB_WORKFLOW_PROCESS = "workflow:process";
export default class PluginWorkflowServer extends Plugin {
instructions: Registry<InstructionInterface>;
triggers: Registry<Trigger>;
functions: Registry<CustomFunction>;
enabledCache: Map<number, WorkflowModel>;
snowflake: Snowflake;
private dispatcher;
readonly timeoutManager: ExecutionTimeoutManager;
readonly runningExecutionRegistry: RunningExecutionRegistry;
get channelPendingExecution(): string;
private loggerCache;
private meter;
private checker;
private onBeforeSave;
private onAfterCreate;
private onAfterUpdate;
private onAfterDestroy;
private onAfterStart;
private onBeforeStop;
handleSyncMessage(message: any): Promise<void>;
serving(): boolean;
abortExecutionIfExpired(execution: ExecutionModel, options?: {
transaction?: Transaction;
}): Promise<boolean>;
registerRunningExecution(executionId: number | string, abort: (reason?: string) => void): void;
unregisterRunningExecution(executionId: number | string): void;
abortRunningExecution(executionId: number | string, reason?: string): boolean;
/**
* @experimental
*/
getLogger(workflowId?: ID): Logger;
/**
* @experimental
* @param {WorkflowModel} workflow
* @returns {boolean}
*/
isWorkflowSync(workflow: WorkflowModel): boolean;
registerTrigger<T extends Trigger>(type: string, trigger: T | {
new (p: Plugin): T;
}): void;
registerInstruction(type: string, instruction: InstructionInterface | {
new (p: Plugin): InstructionInterface;
}): void;
private initTriggers;
private initInstructions;
private registerErrorHandlers;
beforeLoad(): Promise<void>;
/**
* @internal
*/
load(): Promise<void>;
private toggle;
trigger(workflow: WorkflowModel, context: object, options?: EventOptions): void | Promise<Processor | null | void>;
run(pending: Parameters<Dispatcher['run']>[0]): Promise<void>;
dispatch(): void;
resume(job: any): Promise<void>;
/**
* Start a deferred execution
* @experimental
*/
start(execution: ExecutionModel): Promise<void>;
createProcessor(execution: ExecutionModel, options?: {}): Processor;
execute(workflow: WorkflowModel, values: any, options?: EventOptions): Promise<void | Processor>;
/**
* @experimental
* @param {string} dataSourceName
* @param {Transaction} transaction
* @param {boolean} create Create a new transaction when the input transaction does not belong to this data source.
* @returns {Transaction}
*/
useDataSourceTransaction(dataSourceName?: string, transaction?: Transaction | null, create?: false): Transaction | undefined;
useDataSourceTransaction(dataSourceName: string | undefined, transaction: Transaction | null | undefined, create: true): Transaction | Promise<Transaction> | undefined;
/**
* @experimental
*/
updateTasksStats(userId: number, type: string, stats: {
pending: number;
all: number;
}, { transaction }: Transactionable): Promise<void>;
}
export {};