Workflow client allows you to interact with your workflow runs. Currently, it has three basic functionality:

We are planning to add more functionality in the future. See the roadmap for more details.

Cancel Workflow

To cancel a workflow, simply use the cancel method:

import { Client } from "@upstash/workflow";

const client = new Client({ token: "<QSTASH_TOKEN>" })
await client.cancel({ workflowRunId: "<WORKFLOW_RUN_ID>" })

Notify Waiting Workflow

To notify a workflow waiting for an event, you can use the notify method:

import { Client } from "@upstash/workflow";

const client = new Client({ token: "<QSTASH_TOKEN>" })
await client.notify({
  eventId: "my-event-id",
  eventData: "my-data" // data passed to the workflow run
});

The data passed in eventData will be available to the workflow run in the eventData field of the context.waitForEvent method.

Get Waiters of Event

To get the list of waiters for some event id, you can use the getWaiters method:

import { Client } from "@upstash/workflow";

const client = new Client({ token: "<QSTASH_TOKEN>" })
const result = await client.getWaiters({
  eventId: "my-event-id"
})

Result will be a list of Waiter objects:

Waiter