From cde0dee14e0e93018f5d9a5a32a98623ec29bbc4 Mon Sep 17 00:00:00 2001 From: "Ivan A. Melnikov" Date: Fri, 13 Sep 2013 12:22:27 +0400 Subject: Simpler API to load flows into engines Previously to run a flow client code had to put together the flow, an engine, logbook, flowdetail, and storage backend. This commit adds two helper functions, run() and load(), so that simplest usecase now looks like taskflow.engines.run(flow) Client code may also provide configuration for storage and engine if needed, but if not needed it just works with defaults. Engines are loaded via stevedore, as drivers in 'taskflow.engines' backend. Now three entry points are defined in that namespace: - 'default', for SingleThreadedActionEngine, used by default; - 'serial', as another synonym for SingleThreadedActionEngine; - 'parallel', for MultiThreadedActionEngine. Closes-bug: #1224726 Change-Id: I7f4cb5c8ff7f5f12831ddd0952c202d2fd8cd6ef --- taskflow/examples/simple_linear.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'taskflow/examples/simple_linear.py') diff --git a/taskflow/examples/simple_linear.py b/taskflow/examples/simple_linear.py index bde8c64..fb2a7c1 100644 --- a/taskflow/examples/simple_linear.py +++ b/taskflow/examples/simple_linear.py @@ -4,11 +4,12 @@ import sys logging.basicConfig(level=logging.ERROR) -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)) +top_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), + os.pardir, + os.pardir)) +sys.path.insert(0, top_dir) -from taskflow.engines.action_engine import engine as eng +import taskflow.engines from taskflow.patterns import linear_flow as lf from taskflow import task @@ -30,16 +31,11 @@ class CallJoe(task.Task): def execute(self, joe_number, *args, **kwargs): print("Calling joe %s." % joe_number) + flow = lf.Flow('simple-linear').add( CallJim(), CallJoe() ) -engine = eng.SingleThreadedActionEngine(flow) - -engine.storage.inject({ - "joe_number": 444, - "jim_number": 555, -}) - -engine.run() +taskflow.engines.run(flow, store=dict(joe_number=444, + jim_number=555)) -- cgit v1.2.1