In Amazon SWF, can I abuse a Decision task to actually perform the work -


i need amazon swf distribute work, make sure it's done asynchronously, make sure it's store in reliable way , it's automatically restarted. however, workflow logic need extremely simple: it's single task executed.

i implemented way it's supposed done:

  1. request workflow execution
  2. decider founds out , schedules activity
  3. workers finds out activity request, performs results , returns results
  4. decider notices result , copies on in workflow completion

it seems me can have decider work – – , complete workflow execution immediately. take care of a lot of code. (the activity might fail, timeout, etc. things need cater for.)

so question: can have decider performs work , completes 'workflow' immediately?

yes. actually, think came interesting use case: using minimal workflow centralized locking mechanism one-off actions in distributed system - such cron jobs executed single host in fleet of many (the hosts have first undergo election , whichever wins lock gets execute action). same achieved amazon swf , minimum amount of code:

a small python example, using boto.swf (use 1. this post setup domain):

to code decider:

#mydecider.py import boto.swf.layer2 swf  class oneshotdecider(swf.decider):      domain = 'stackoverflow'     task_list = 'default_tasks'     version = '1.0'      def run(self):         history = self.poll()         if 'events' in history:             decisions = swf.layer1decisions()             print 'got decision task, doing work'             decisions.complete_workflow_execution()             self.complete(decisions=decisions)             return false         return true 

to start decider:

$ ipython -i decider.py in [1]: while oneshotdecider().run(): print 'polling swf decision tasks' 

finally, start workflow:

$ ipython in [1]: wf_type = swf.workflowtype(domain='stackoverflow', name='myworkflow', version='1.0', task_list='default_tasks')  in [2]: wf_type.start() out[2]: <workflowexecution 'myworkflow-1.0' @ 0x32e2a10> 

back in decider window, you'll see like:

polling swf decision tasks polling swf decision tasks got decision task, doing work 

if workflow evolve business logic or grow in number of activities, it's best stick standard way of having deciders doing business logic , workers solving tasks.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -