@hotmeshio/hotmesh
Version:
Serverless Workflow
125 lines (124 loc) • 3.25 kB
TypeScript
import { HotMesh } from '../hotmesh';
import { Connection, Registry, WorkerConfig, WorkerOptions } from '../../types/meshflow';
/**
* The *Worker* service Registers worker functions and connects them to the mesh,
* using the target backend provider/s (Redis, Postgres, NATS, etc).
*
* @example
* ```typescript
* import { MeshFlow } from '@hotmeshio/hotmesh';
* import { Client as Postgres } from 'pg';
* import * as workflows from './workflows';
*
* async function run() {
* const worker = await MeshFlow.Worker.create({
* connection: {
* class: Postgres,
* options: { connectionString: 'postgres://user:password@localhost:5432/db' }
* },
* taskQueue: 'default',
* workflow: workflows.example,
* });
*
* await worker.run();
* }
* ```
*/
export declare class WorkerService {
/**
* @private
*/
static activityRegistry: Registry;
/**
* @private
*/
static instances: Map<string, HotMesh | Promise<HotMesh>>;
/**
* @private
*/
workflowRunner: HotMesh;
/**
* @private
*/
activityRunner: HotMesh;
/**
* @private
*/
static getHotMesh: (workflowTopic: string, config?: Partial<WorkerConfig>, options?: WorkerOptions) => Promise<HotMesh>;
static hashOptions(connection: Connection): string;
/**
* @private
*/
constructor();
/**
* @private
*/
static activateWorkflow(hotMesh: HotMesh): Promise<void>;
/**
* @private
*/
static registerActivities<ACT>(activities: ACT): Registry;
/**
* Connects a worker to the mesh.
*
* @example
* ```typescript
* import { MeshFlow } from '@hotmeshio/hotmesh';
* import { Client as Postgres } from 'pg';
* import * as workflows from './workflows';
*
* async function run() {
* const worker = await MeshFlow.Worker.create({
* connection: {
* class: Postgres,
* options: {
* connectionString: 'postgres://user:password@localhost:5432/db'
* },
* },
* taskQueue: 'default',
* workflow: workflows.example,
* });
*
* await worker.run();
* }
* ```
*/
static create(config: WorkerConfig): Promise<WorkerService>;
/**
* @private
*/
static resolveWorkflowTarget(workflow: object | Function, name?: string): [string, Function];
/**
* Run the connected worker; no-op (unnecessary to call)
*/
run(): Promise<void>;
/**
* @private
*/
initActivityWorker(config: WorkerConfig, activityTopic: string): Promise<HotMesh>;
/**
* @private
*/
wrapActivityFunctions(): Function;
/**
* @private
*/
initWorkflowWorker(config: WorkerConfig, workflowTopic: string, workflowFunction: Function): Promise<HotMesh>;
/**
* @private
*/
static Context: {
info: () => {
workflowId: string;
workflowTopic: string;
};
};
/**
* @private
*/
wrapWorkflowFunction(workflowFunction: Function, workflowTopic: string, config: WorkerConfig): Function;
/**
* @private
*/
static shutdown(): Promise<void>;
}