简体   繁体   中英

Amazon AWS Simple Workflow Service SWF C# Sample

I was wondering if there are any SWF workflow C# sample code available for the AWS .NET SDK?

AWS Forum Post: https://forums.aws.amazon.com/thread.jspa?threadID=122216&tstart=0

As part of getting familiar with SWF, I ended up writing a common case library that I hope others can use as well. It's called SimpleWorkflowFramework.NET and is available as open source at https://github.com/sdebnath/SimpleWorkflowFramework.NET . It definitely could use a lot of help, so if you are interested, jump right in! :)

I have developed an open source .NET library- Guflow to program Amazon SWF. Here is how you can write a workflow to transcode the video:

[WorkflowDescription("1.0")]
public class TranscodeWorkflow : Workflow
{
  public TranscodeWorkflow()
  {
    //DownloadActivity is the startup activity and will be scheduled when workflow is started.
    ScheduleActivity<DownloadActivity>().OnFailure(Reschedule);

    //After DownloadActivity is completed TranscodeActivity activity will be scheduled.
    ScheduleActivity<TranscodeActivity>().AfterActivity<DownloadActivity>()
        .WithInput(a => new {InputFile = ParentResult(a).DownloadedFile, Format = "MP4"})

    ScheduleActivity<UploadToS3Activity>().AfterActivity<TranscodeActivity>()
        .WithInput(a => new {InputFile = ParentResult(a).TranscodedFile});

    ScheduleActivity<SendConfirmationActivity>().AfterActivity<UploadToS3Activity>();
  }
  private static dynamic ParentResult(IActivityItem a) => a.ParentActivity().Result();
}

In above example I have left out task routing for clarity. Here is how you can create an activity:

[ActivityDescription("1.0")]
public class DownloadActivity : Activity
{
  //It supports both sync/async method.
  [ActivityMethod]
  public async Task<Response> Execute(string input)
  {
      //simulate downloading of file
      await Task.Delay(10);
      return new Response() { DownloadedFile = "downloaded path", PollingQueue = PollingQueue.Download};
  }

  public class Response
  {
      public string DownloadedFile;
  }
}

For clarity I'm leaving out examples of other activities. Guflow it supported by documentation , tutorial and samples .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM