summaryrefslogtreecommitdiff
path: root/taskflow/examples/reverting_linear.py
diff options
context:
space:
mode:
authorAnastasia Karpinska <akarpinska@griddynamics.com>2013-09-04 11:27:39 +0400
committerIvan A. Melnikov <imelnikov@griddynamics.com>2013-09-04 19:33:12 +0400
commita638c9864f8d5f050fc59be1a84e728e30f981aa (patch)
tree84c894061c8016110dc2e20e101fb16b23d9e6a2 /taskflow/examples/reverting_linear.py
parent6ee4d32fc25a7343ef4802f8390e76ef608106b9 (diff)
downloadtaskflow-a638c9864f8d5f050fc59be1a84e728e30f981aa.tar.gz
Converted some examples to use patterns/engines
Change-Id: If7154019f1cb5e723069ff35f6301fce048323b5
Diffstat (limited to 'taskflow/examples/reverting_linear.py')
-rw-r--r--taskflow/examples/reverting_linear.py52
1 files changed, 28 insertions, 24 deletions
diff --git a/taskflow/examples/reverting_linear.py b/taskflow/examples/reverting_linear.py
index 36164b5..0a34a1b 100644
--- a/taskflow/examples/reverting_linear.py
+++ b/taskflow/examples/reverting_linear.py
@@ -8,44 +8,48 @@ my_dir_path = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(os.path.join(my_dir_path, os.pardir),
os.pardir))
-from taskflow import decorators
-from taskflow.patterns import linear_flow as lf
+from taskflow import blocks
+from taskflow.engines.action_engine import engine as eng
+from taskflow import task
-def undo_call(context, result, cause):
- print("Calling %s and apologizing." % result)
+class CallJim(task.Task):
+ def execute(self, jim_number, *args, **kwargs):
+ print("Calling jim %s." % jim_number)
+ def revert(self, jim_number, *args, **kwargs):
+ print("Calling %s and apologizing." % jim_number)
-@decorators.task(revert=undo_call)
-def call_jim(context):
- print("Calling jim.")
- print("Context = %s" % (context))
- return context['jim_number']
+class CallJoe(task.Task):
+ def execute(self, joe_number, *args, **kwargs):
+ print("Calling joe %s." % joe_number)
-@decorators.task(revert=undo_call)
-def call_joe(context):
- print("Calling joe.")
- print("Context = %s" % (context))
- return context['joe_number']
+ def revert(self, joe_number, *args, **kwargs):
+ print("Calling %s and apologizing." % joe_number)
-@decorators.task
-def call_suzzie(context):
- raise IOError("Suzzie not home right now.")
+class CallSuzzie(task.Task):
+ def execute(self, suzzie_number, *args, **kwargs):
+ raise IOError("Suzzie not home right now.")
+ def revert(self, suzzie_number, *args, **kwargs):
+ # TODO(imelnikov): this method should not be requred
+ pass
-flow = lf.Flow("call-them")
-flow.add(call_jim)
-flow.add(call_joe)
-flow.add(call_suzzie)
-context = {
+flow = blocks.LinearFlow().add(blocks.Task(CallJim),
+ blocks.Task(CallJoe),
+ blocks.Task(CallSuzzie))
+engine = eng.SingleThreadedActionEngine(flow)
+
+engine.storage.inject({
"joe_number": 444,
"jim_number": 555,
-}
+ "suzzie_number": 666
+})
try:
- flow.run(context)
+ engine.run()
except Exception as e:
print "Flow failed: %r" % e