Just released version - 2.0.5 of
Guflow has added the support for timeout in signal APIs. Now with minimum efforts you can support the human interactions in your workflows. Following example uses timeout API to ensure that user should confirm her email address within 12 hours to activate the account:
public class UserActivateWorkflow : Workflow{
public UserActivateWorkflow(){
ScheduleLambda("SendLinkInEmail").WithInput(_=>{Id=Id})
.OnCompletion(e=>e.WaitForSignal("EmailConfirmed").For(Timespan.FromHours(12)));
ScheduleLambda("ActivateAccount").AfterLambda("SendLinkInEmail")
.When(_=>Signal("EmailConfirmed").IsTriggered());
ScheduleLambda("ActivationFailed").WithInput(_=>{ Reason="Link timedout"})
.AfterLambda("SendLinkInEmail")
.When(_=>Signal("EmailConfirmed").IsTimedout())
}
}
Timeout is supported for all the wait for signal APIs: WaitForSignal, WaitForAnySignal and WaitForAllSignals. You can read more about them
here.
Feature highlights:
1. Though default implementation of "wait for signal" APIs should be sufficient for real world scenarios but Guflow also support
customization.
2. Signal APIs automatically adjust the wait time to cater for the downtime of the workflow host. e.g. in above example wait APIs will adjust the wait time to 11 hours if workflow host was down for 1 hour just after executing the Lambda function "SendLinkInEmail". It means user will really have 12 hours to confirm email and timeout will not be automatically inflated because your workflow host was down.
3. Like rest of of APIs, signal APIs too store their state in Amazon SWF which means your workflow host is stateless and you have the flexibility to upsize/downsize/upgrade in production.
4. You can also use
alternative style to detect trigger and timeout for the signals as shown in the following example:
public class UserActivateWorkflow : Workflow{
public UserActivateWorkflow(){
ScheduleLambda("SendLinkInEmail").WithInput(_=>{Id=Id})
.OnCompletion(e=>e.WaitForSignal("EmailConfirmed").For(Timespan.FromHours(12)));
ScheduleLambda("ActivateAccount").AfterLambda("SendLinkInEmail")
.When(_=>Lambda("SendLinkInEmail").IsSignalled("EmailConfirmed"));
ScheduleLambda("ActivationFailed").WithInput(_=>{ Reason="Link timedout"})
.AfterLambda("SendLinkInEmail")
.When(_=>Lambda("SendLinkInEmail").IsSignalTimedout("EmailConfirmed"))
}
}
Last few releases of Guflow were targeted to enhance signal handling capability. You can use signals for the following three purposes:
Hope you'll like the new feature.