
In order to move away from the existing flows having their own implementation of running, start moving the existing flows to be patterns that only structure tasks (and impose constraints about how the group of tasks can run) in useful ways. Let the concept of running those patterns be handled by an engine instead of being handled by the flow itself. This will allow for varying engines to be able to run flows in whichever way the engine chooses (as long as the constraints set up by the flow are observed). Currently threaded flow and graph flow are broken by this commit, since they have not been converted to being a structure of tasks + constraints. The existing engine has not yet been modified to run those structures either, work is underway to remediate this. Part of: blueprint patterns-and-engines Followup bugs that must be addressed: Bug: 1221448 Bug: 1221505 Change-Id: I3a8b96179f336d1defe269728ebae0caa3d832d7
46 lines
970 B
Python
46 lines
970 B
Python
import logging
|
|
import os
|
|
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))
|
|
|
|
from taskflow.engines.action_engine import engine as eng
|
|
from taskflow.patterns import linear_flow as lf
|
|
from taskflow import task
|
|
|
|
|
|
class CallJim(task.Task):
|
|
|
|
def __init__(self):
|
|
super(CallJim, self).__init__()
|
|
|
|
def execute(self, jim_number, *args, **kwargs):
|
|
print("Calling jim %s." % jim_number)
|
|
|
|
|
|
class CallJoe(task.Task):
|
|
|
|
def __init__(self):
|
|
super(CallJoe, self).__init__()
|
|
|
|
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()
|