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.

import { MeshFlow } from '@hotmeshio/hotmesh';

const client = new MeshFlow.Client({ connection: { class: Redis, options } });
const handle = await client.workflow.start({
args: ['HotMesh'],
taskQueue: 'hello-world',
});

//perform actions like send a signal
await handle.signal('my-signal', { data: 'Hello' });

Properties

hotMesh: HotMesh
workflowId: string
workflowTopic: string

Methods

  • Interrupts a running workflow. Standard Job Completion tasks will run. Subscribers will be notified and the job hash will be expired.

    Parameters

    Returns Promise<string>

  • 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. As the workflow is stored in a Redis hash, this is a way to store additional data that is indexed and searchable using the RediSearch module.

    Parameters

    • fields: string[]

    Returns Promise<Record<string, any>>

  • 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.

    Type Parameters

    • T

    Parameters

    • Optionalconfig: {
          state?: boolean;
          throwOnError?: boolean;
      }
      • Optionalstate?: boolean
      • OptionalthrowOnError?: boolean

    Returns Promise<StreamError | T>

  • 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.

    Parameters

    • signalId: string
    • data: Record<any, any>

    Returns 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.

    Parameters

    • metadata: boolean = false

    Returns 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.

    Returns Promise<number>