Merge "Use the class defined constant instead of raw strings"
This commit is contained in:
@@ -7,6 +7,8 @@ Notifications and listeners
|
|||||||
from taskflow import task
|
from taskflow import task
|
||||||
from taskflow.patterns import linear_flow
|
from taskflow.patterns import linear_flow
|
||||||
from taskflow import engines
|
from taskflow import engines
|
||||||
|
from taskflow.types import notifier
|
||||||
|
ANY = notifier.Notifier.ANY
|
||||||
|
|
||||||
--------
|
--------
|
||||||
Overview
|
Overview
|
||||||
@@ -57,7 +59,7 @@ A basic example is:
|
|||||||
>>> flo = linear_flow.Flow("cat-dog").add(
|
>>> flo = linear_flow.Flow("cat-dog").add(
|
||||||
... CatTalk(), DogTalk(provides="dog"))
|
... CatTalk(), DogTalk(provides="dog"))
|
||||||
>>> eng = engines.load(flo, store={'meow': 'meow', 'woof': 'woof'})
|
>>> eng = engines.load(flo, store={'meow': 'meow', 'woof': 'woof'})
|
||||||
>>> eng.notifier.register("*", flow_transition)
|
>>> eng.notifier.register(ANY, flow_transition)
|
||||||
>>> eng.run()
|
>>> eng.run()
|
||||||
Flow 'cat-dog' transition to state RUNNING
|
Flow 'cat-dog' transition to state RUNNING
|
||||||
meow
|
meow
|
||||||
@@ -93,7 +95,7 @@ A basic example is:
|
|||||||
>>> flo.add(CatTalk(), DogTalk(provides="dog"))
|
>>> flo.add(CatTalk(), DogTalk(provides="dog"))
|
||||||
<taskflow.patterns.linear_flow.Flow object at 0x...>
|
<taskflow.patterns.linear_flow.Flow object at 0x...>
|
||||||
>>> eng = engines.load(flo, store={'meow': 'meow', 'woof': 'woof'})
|
>>> eng = engines.load(flo, store={'meow': 'meow', 'woof': 'woof'})
|
||||||
>>> eng.task_notifier.register("*", task_transition)
|
>>> eng.task_notifier.register(ANY, task_transition)
|
||||||
>>> eng.run()
|
>>> eng.run()
|
||||||
Task 'CatTalk' transition to state RUNNING
|
Task 'CatTalk' transition to state RUNNING
|
||||||
meow
|
meow
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ import taskflow.engines
|
|||||||
from taskflow.patterns import graph_flow as gf
|
from taskflow.patterns import graph_flow as gf
|
||||||
from taskflow.patterns import linear_flow as lf
|
from taskflow.patterns import linear_flow as lf
|
||||||
from taskflow import task
|
from taskflow import task
|
||||||
|
from taskflow.types import notifier
|
||||||
|
|
||||||
|
ANY = notifier.Notifier.ANY
|
||||||
|
|
||||||
import example_utils as eu # noqa
|
import example_utils as eu # noqa
|
||||||
|
|
||||||
@@ -160,11 +163,11 @@ spec = {
|
|||||||
|
|
||||||
engine = taskflow.engines.load(flow, store={'spec': spec.copy()})
|
engine = taskflow.engines.load(flow, store={'spec': spec.copy()})
|
||||||
|
|
||||||
# This registers all (*) state transitions to trigger a call to the flow_watch
|
# This registers all (ANY) state transitions to trigger a call to the
|
||||||
# function for flow state transitions, and registers the same all (*) state
|
# flow_watch function for flow state transitions, and registers the
|
||||||
# transitions for task state transitions.
|
# same all (ANY) state transitions for task state transitions.
|
||||||
engine.notifier.register('*', flow_watch)
|
engine.notifier.register(ANY, flow_watch)
|
||||||
engine.task_notifier.register('*', task_watch)
|
engine.task_notifier.register(ANY, task_watch)
|
||||||
|
|
||||||
eu.print_wrapped("Building a car")
|
eu.print_wrapped("Building a car")
|
||||||
engine.run()
|
engine.run()
|
||||||
@@ -176,8 +179,8 @@ engine.run()
|
|||||||
spec['doors'] = 5
|
spec['doors'] = 5
|
||||||
|
|
||||||
engine = taskflow.engines.load(flow, store={'spec': spec.copy()})
|
engine = taskflow.engines.load(flow, store={'spec': spec.copy()})
|
||||||
engine.notifier.register('*', flow_watch)
|
engine.notifier.register(ANY, flow_watch)
|
||||||
engine.task_notifier.register('*', task_watch)
|
engine.task_notifier.register(ANY, task_watch)
|
||||||
|
|
||||||
eu.print_wrapped("Building a wrong car that doesn't match specification")
|
eu.print_wrapped("Building a wrong car that doesn't match specification")
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ sys.path.insert(0, top_dir)
|
|||||||
import taskflow.engines
|
import taskflow.engines
|
||||||
from taskflow.patterns import linear_flow as lf
|
from taskflow.patterns import linear_flow as lf
|
||||||
from taskflow import task
|
from taskflow import task
|
||||||
|
from taskflow.types import notifier
|
||||||
|
|
||||||
|
ANY = notifier.Notifier.ANY
|
||||||
|
|
||||||
# INTRO: In this example we create two tasks (this time as functions instead
|
# INTRO: In this example we create two tasks (this time as functions instead
|
||||||
# of task subclasses as in the simple_linear.py example), each of which ~calls~
|
# of task subclasses as in the simple_linear.py example), each of which ~calls~
|
||||||
@@ -92,8 +95,8 @@ engine = taskflow.engines.load(flow, store={
|
|||||||
# notification objects that a engine exposes. The usage of a '*' (kleene star)
|
# notification objects that a engine exposes. The usage of a '*' (kleene star)
|
||||||
# here means that we want to be notified on all state changes, if you want to
|
# here means that we want to be notified on all state changes, if you want to
|
||||||
# restrict to a specific state change, just register that instead.
|
# restrict to a specific state change, just register that instead.
|
||||||
engine.notifier.register('*', flow_watch)
|
engine.notifier.register(ANY, flow_watch)
|
||||||
engine.task_notifier.register('*', task_watch)
|
engine.task_notifier.register(ANY, task_watch)
|
||||||
|
|
||||||
# And now run!
|
# And now run!
|
||||||
engine.run()
|
engine.run()
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ from taskflow import task
|
|||||||
from taskflow.types import notifier
|
from taskflow.types import notifier
|
||||||
from taskflow.utils import threading_utils
|
from taskflow.utils import threading_utils
|
||||||
|
|
||||||
|
ANY = notifier.Notifier.ANY
|
||||||
|
|
||||||
# INTRO: This examples shows how to use a remote workers event notification
|
# INTRO: This examples shows how to use a remote workers event notification
|
||||||
# attribute to proxy back task event notifications to the controlling process.
|
# attribute to proxy back task event notifications to the controlling process.
|
||||||
#
|
#
|
||||||
@@ -94,7 +96,7 @@ WORKER_CONF = {
|
|||||||
|
|
||||||
def run(engine_options):
|
def run(engine_options):
|
||||||
reporter = EventReporter()
|
reporter = EventReporter()
|
||||||
reporter.notifier.register(notifier.Notifier.ANY, event_receiver)
|
reporter.notifier.register(ANY, event_receiver)
|
||||||
flow = lf.Flow('event-reporter').add(reporter)
|
flow = lf.Flow('event-reporter').add(reporter)
|
||||||
eng = engines.load(flow, engine='worker-based', **engine_options)
|
eng = engines.load(flow, engine='worker-based', **engine_options)
|
||||||
eng.run()
|
eng.run()
|
||||||
|
|||||||
Reference in New Issue
Block a user