Skip to content

Return ad hoc workflow action

Gurmit Teotia edited this page Nov 17, 2022 · 10 revisions

On receiving a signal you can interrupt the workflow execution or schedule any workflow item. You need to define the signal event handler as explained here.

In the following example workflow is cancelled on receiving the "CancelOrder" signal if the order is cancelled within grace period:

public class OrderWorkflow :Workflow
{
  public OrderWorkflow()
  {
   ScheduleTimer("GracePeriod").FireAfter(TimeSpan.FromHours(1)); 
   ScheduleLambda("ReserveOrder").AfterTimer("GracePeriod");
   ScheduleLambda("OrderCancelled").AfterTimer("GracePeriod").When(_=>false);
   ScheduleLambda("ShipOrder").AfterLambda("ReserveOrder");
  }
  [SignalEvent]
  public WorkflowAction CancelOrder() 
  {
    var timer = Timer("GracePeriod");
    if timer.IsActive()
      return CancelRequest.For(timer) + Jump.ToLambda("OrderCancelled");
    return Ignore;
  }
}
Clone this wiki locally