@hotmeshio/hotmesh
Version:
Serverless Workflow
91 lines (90 loc) • 3.3 kB
TypeScript
import { HotMesh } from '../hotmesh';
import { MeshFlowJobExport, ExportOptions } from '../../types/exporter';
import { JobInterruptOptions } from '../../types/job';
import { StreamError } from '../../types/stream';
import { ExporterService } from './exporter';
/**
* The WorkflowHandleService provides methods to interact with a running
* workflow. This includes exporting the workflow, sending signals, and
* querying the state of the workflow. It is instanced/accessed via the
* MeshFlow.Client class.
*
* @example
* ```typescript
* import { Client } from '@hotmeshio/hotmesh';
* import { Client as Postgres } from 'pg';
*
* const client = new Client({ connection: {
* class: Postgres,
* options: { connectionString: 'postgres://user:pass@localhost:5432/db' }
* }});
*
* const handle = await client.workflow.start({
* args: ['HotMesh'],
* taskQueue: 'hello-world',
* });
*
* //perform actions like send a signal
* await handle.signal('my-signal', { data: 'Hello' });
* ```
*/
export declare class WorkflowHandleService {
/**
* @private
*/
exporter: ExporterService;
hotMesh: HotMesh;
workflowTopic: string;
workflowId: string;
/**
* @private
*/
constructor(hotMesh: HotMesh, workflowTopic: string, workflowId: string);
/**
* Exports the workflow state to a JSON object.
*/
export(options?: ExportOptions): Promise<MeshFlowJobExport>;
/**
* Sends a signal to the workflow. This is a way to send
* a message to a workflow that is paused due to having
* executed `MeshFlow.workflow.waitFor`. The workflow
* will awaken if no other signals are pending.
*/
signal(signalId: string, data: Record<any, any>): Promise<void>;
/**
* Returns the job state of the workflow. If the workflow has completed
* this is also the job output. If the workflow is still running, this
* is the current state of the job, but it may change depending upon
* the activities that remain.
*/
state(metadata?: boolean): Promise<Record<string, any>>;
/**
* Returns the current search state of the workflow. This is
* different than the job state or individual activity state.
* Search state represents name/value pairs that were added
* to the workflow.
*/
queryState(fields: string[]): Promise<Record<string, any>>;
/**
* Returns the current status of the workflow. This is a semaphore
* value that represents the current state of the workflow, where
* 0 is complete and a negative value represents that the flow was
* interrupted.
*/
status(): Promise<number>;
/**
* Interrupts a running workflow. Standard Job Completion tasks will
* run. Subscribers will be notified and the job hash will be expired.
*/
interrupt(options?: JobInterruptOptions): Promise<string>;
/**
* Waits for the workflow to complete and returns the result. If
* the workflow response includes an error, this method will rethrow
* the error, including the stack trace if available.
* Wrap calls in a try/catch as necessary to avoid unhandled exceptions.
*/
result<T>(config?: {
state?: boolean;
throwOnError?: boolean;
}): Promise<T | StreamError>;
}