Cancellation Management

Infinitic is still in active development. Subscribe here to follow the progress.

What happens if a task dispatched by a workflow is canceled?

  • if the task was dispatched asynchronously (using async function), it won't impact the workflow processing
  • if the task was dispatched synchronously, then an CanceledDeferredException will throw in the workflow. Then:
    • if the CanceledDeferredException is caught within the workflow, it will continue
    • if not, then the workflow will stop. From there, we have two possibilities to clean up the situation:
      • cancel the workflow entirely
      • update the workflow to add a try / catch statement and retry the workflow itself
// a cancellation of this task
// won't impact the workflow
async(task, t -> t.method(parameters);

// a cancellation of this task
// will throw a CanceledDeferredException here
task.method(parameters);

async(() -> {
    ...
    // a cancellation of this task
    // will throw a CanceledDeferredException here
    // and stop only this part of the workflow
    task.method();
    ....
});

// a cancellation of this task
// will be caught and the workflow will continue
try {
    task.method(parameters);
} catch(CanceledDeferredException e) {
    ...
}
// a cancellation of this task
// won't impact the workflow
async(task) { method(parameters) }

// a cancellation of this task
// will throw a CanceledDeferredException here
task.method(parameters)

async {
    ...
    // a cancellation of this task
    // will throw a CanceledDeferredException here
    // and stop only this part of the workflow
    task.method(parameters)
    ...
}

// a cancellation of this task
// will be caught and the workflow will continue
try {
    task.method(parameters)
} catch(e: FailedDeferredException) {
    ...
}

Notes:

  • if the workflow is itself a child-workflow, and the canceled non-caught synchronous task is on the main execution path of the workflow (not within an async), then this workflow will appear as failed for its parent (and maybe for the parent' s parent, and so on)

  • if a asynchronous task is canceled, and we apply later the await() method on it, the CanceledDeferredException will throw:

    // a cancellation of this task
    // won't impact the workflow
    Deferred<*> deferred = async(task, t -> t.method(parameters);
    
    ...
    
    // a CanceledDeferredException throws
    // and the workflow will stop here
    deferred.await();
    
    // a cancellation of this task
    // won't impact the workflow
    aval deferred = sync(task) { method(parameters) }
    
    ...
    
    // a CanceledDeferredException throws
    // and the workflow will stop here
    deferred.await()
    

CanceledDeferredException and FailedDeferredException are the only exceptions relevant in workflows. You must not catch any other exception.

Edit this page on GitHub Updated at Fri, May 28, 2021