Skip to content

Part 4 Error handling

Gurmit Teotia edited this page Jan 17, 2018 · 8 revisions

Guflow reports errors using two styles- events and exceptions. You can read more about error handling in wiki.

In this part of tutorial we will handle the error events.

  • If DownloadActivity has failed to download the file, we want to reschedule it.
  • If TranscodeActivity or UploadToS3Activity has timedout then depending on error we either want to reschedule them or restart the whole workflow. In this case we will restart the whole workflow.
[WorkflowDescription("1.0")]
public class TranscodeWorkflow : WorkflowDescription
{
  public TranscodeWorkflow()
  {
    //DownloadActivity will be scheduled on its default task list
	ScheduleActivity<DownloadActivity>()
			.OnFailure(a=>Reschedule(a).After(Timespan.FromSeconds(2)).UpTo(Limit.Count(3));
	 
	//TranscodeActivity will be scheduled on machine where download activity has executed. 
	ScheduleActivity<TranscodeActivity>().AfterActivity<DownloadFile>()
		.OnTaskList(a=>a.Parent().Result().PollingQueue)
		.WithInput(a=> new { InputFile=a.Parent().Result().DownloadedFile, Format ="MP4});
		.OnTimeout(a=>RestartWorkflow());
	
    //TranscodeActivity will be scheduled on machine where download activity has executed.	
	ScheduleActivity<UploadToS3Activity>().AfterActivity<TranscodeActivity>()
	    .OnTaskList(_=>Activity<DownloadActivity>().Result().PollingQueue)
		.WithInput(a=> new { InputFile=a.Parent().Result().TranscodedFile});
		.OnTimeout(a=>RestartWorkflow());
	 
    //SendConfirmationActivity can be executed on any worker machine	 
	ScheduleActivity<SendConfirmationActivity>().AfterActivity<UploadToS3Activity>();
  }  
}

You can see the complete source code for this tutorial at github.

I hope this tutorial has given you a head start in Guflow library. You can read the more details documents in wiki

Clone this wiki locally