• Terminates a running workflow job by its ID. The target job's status is set to an error code indicating abnormal termination, and any pending activities or timers are cancelled.

    This is the workflow-internal terminate — it can only be called from within a workflow function. For external termination, use handle.terminate() directly.

    The terminate fires exactly once per workflow execution — the isSideEffectAllowed guard prevents re-terminating on replay.

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

    // Terminate a child workflow from the parent
    export async function supervisorWorkflow(): Promise<void> {
    const childId = await Durable.workflow.startChild({
    taskQueue: 'workers',
    workflowName: 'longTask',
    args: [],
    });

    // Wait for a timeout, then terminate the child
    await Durable.workflow.sleep('5 minutes');
    await Durable.workflow.terminate(childId, {
    reason: 'Timed out waiting for child',
    descend: true, // also terminate any grandchild workflows
    });
    }
    // Self-terminate on validation failure
    export async function validatedWorkflow(input: string): Promise<void> {
    const { workflowId } = Durable.workflow.workflowInfo();
    const { validate } = Durable.workflow.proxyActivities<typeof activities>();

    const isValid = await validate(input);
    if (!isValid) {
    await Durable.workflow.terminate(workflowId, {
    reason: 'Invalid input',
    });
    }
    }

    Parameters

    • jobId: string

      The ID of the workflow job to terminate.

    • Optionaloptions: JobInterruptOptions = {}

      Termination options (reason, descend, etc.).

    Returns Promise<string | void>

    The result of the termination, if any.