Yes. In fact, I think you created an interesting precedent: the use of a minimal workflow as a centralized mechanism for blocking one-time actions in a distributed system - for example, cron jobs executed from one host in a fleet of many (hosts have to go through elections first and depending on which win is blocked to perform an action). The same could be done with Amazon SWF and a minimal amount of code:
A small Python example using boto.swf (use 1. from this post to configure the domain):
To program a solution:
#MyDecider.py import boto.swf.layer2 as 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 the decision task, doing the work' decisions.complete_workflow_execution() self.complete(decisions=decisions) return False return True
To run the solution:
$ ipython -i decider.py In [1]: while OneShotDecider().run(): print 'polling SWF for decision tasks'
Finally, to start the 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' at 0x32e2a10>
In the solver window, you will see something like:
polling SWF for decision tasks polling SWF for decision tasks got the decision task, doing the work
If your workflow is likely to change your business logic or increase in the number of actions, it is probably best to stick to the standard way of making business logic and work decisions when solving problems.
source share