1. MooseStack
  2. Moose Workflows
  3. Cancel Workflows

On this page

Implementing Cancelation Callbacks

Cancel a Running Workflow

To stop a workflow before it has finished running, use the workflow cancel command.

moose workflow cancel <workflow-name>

Implementing Cancelation Callbacks

For workflows that are running and have clean up operations to perform, you can implement a termination callback.

This is especially useful for any long running tasks that have open connections or subscriptions to other services that need to be closed. You may also use the state within the run/cancel context to supplement your business logic.

const task1 = new Task<Foo, void>({  name: "task1",  run: async (ctx) => {    connection.open();  },  onCancel: async (ctx) => {    // Clean up any resources    connection.close();  },}); const myworkflow = new Workflow({  name: "myworkflow",  startingTask: task1,  retries: 3,});
const task1 = new Task<Foo, void>({  name: "task1",  run: async (ctx) => {    connection.open();  },  onCancel: async (ctx) => {    // Clean up any resources    connection.close();  },}); const myworkflow = new Workflow({  name: "myworkflow",  startingTask: task1,  retries: 3,});
  • Overview
  • Quick Start
  • Templates / Examples
Fundamentals
  • Moose Runtime
  • MooseDev MCP
  • Data Modeling
MooseStack in your App
  • App / API frameworks
Modules
  • Moose OLAP
  • Moose Streaming
  • Moose Workflows
    • Define Workflows
    • Scheduling
    • Triggers
    • Retries and Timeouts
    • Cancelling Running Workflows
  • Moose APIs
Deployment & Lifecycle
  • Moose Migrate
  • Moose Deploy
Reference
  • API Reference
  • Data Types
  • Table Engines
  • CLI
  • Configuration
  • Observability Metrics
  • Help
  • Changelog
Contribution
  • Documentation
  • Framework
FiveonefourFiveonefour
Fiveonefour Docs
MooseStackTemplates
Changelog
Source506