Repository navigation
Workflow input
When starting a workflow you have the option to provide the workflow input as primitive type - int, float,bool... or as complex type in JSON format. In workflow there are three easy ways to access the workflow input:
-
Use Workflow.Input property: Workflow.Input returns dynamic object. You can use it to access both primitive and complex workflow input. Complex workflow input must be in JSON format.
var domain = new Domain("test", RegionEndpoint.EUWest1); //following API will start the workflow with complex input var startRequest = WorkflowStartRequest.For<BookingWorkflow>("id"); startRequest.Input = new {BookFlight = true, BookHotel = false}; await domain.StartWorkflowAsync(startRequest); //You can access and use workflow input as show below [WorkflowDescription("1.0")] public class BookingWorkflow : Workflow { public BookingWorkflow() { ScheduleActivity<BookFlight>().When(_=>Input.BookFlight); .... ScheduleActivity<BookHotel>().When(_=>Input.BookHotel); .... } }
-
Use Workflow.InputAs method: Returns the deserialized custom object from workflow input. It support deserialization into primitive and custom type. For custom input, workflow must be started with JSON format input. Following example clarify it further
var domain = new Domain("test", RegionEndpoint.EUWest1); //following API will start the workflow with complex input var startRequest = WorkflowStartRequest.For<BookingWorkflow>("id"); startRequest.Input = new BookingInput{BookFlight = true, BookHotel = false}; await domain.StartWorkflowAsync(startRequest); //You can access and use workflow input as show below [WorkflowDescription("1.0")] public class BookingWorkflow : Workflow { public BookingWorkflow() { ScheduleActivity<BookFlight>().When(_=>InputAs<BookingInput>.BookFlight); .... ScheduleActivity<BookHotel>().When(_=>InputAs<BookingInput>.BookHotel); .... } }
-
Use raw format input: You can access raw form input by directly accessing the WorkflowStartedEvent as shown in below example.
[WorkflowDescription("1.0")] public class CustomWorkflow : Workflow { private string RawInput => StartedEvent.Input; }
You can also replace default Workflow.Input property with your property to return the custom object as shown in following example:
[WorkflowDescription("1.0")]
public class BookingWorkflow : Workflow
{
public BookingWorkflow()
{
ScheduleActivity<BookFlight>().When(_=>Input.BookFlight);
....
ScheduleActivity<BookHotel>().When(_=>Input.BookHotel);
....
}
protected new BookingInput Input => InputAs<BookingInput>();
}Guflow
- Prerequisite
- Installation
-
Workflows
- Creating first workflow
- Registration
- Hosting
- Start workflow
- Schedule activities
- Schedule timers
- Schedule lambda function
- Schedule child workflows
- Lambda functions vs activities
- Workflow input
- Workflow actions
- Signals
- Workflow branches
- Deflow algorithm
- Workflow events
- Query APIs
- Custom polling strategy
- Things to take care of
- Activites
- Unit testing
- Performance & scalability
- Error handling
- Logging
- Debugging
- Tutorial
- Release notes