summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-01-29 15:11:41 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2015-01-29 15:17:33 -0800
commit43d70ebe773b7f40afba108e962d68f1fe1c6ff3 (patch)
tree2b8d888f762d55ba34458ee5fce1b3e9dc0ca608
parent708b01ec1240b5d28c19e4a8bf99f1a3d7c4912f (diff)
downloadtaskflow-43d70ebe773b7f40afba108e962d68f1fe1c6ff3.tar.gz
Use the class defined constant instead of raw strings
In examples and documentation it is better if we recommend good practices for using the notifications and the good/better practice would be to use the class defined constant instead of using a raw string (in-case taskflow ever changes that constant value sometime in the future). Change-Id: Ied8fc88747f8635de4aa776095e7e0195d6043aa
-rw-r--r--doc/source/notifications.rst6
-rw-r--r--taskflow/examples/build_a_car.py17
-rw-r--r--taskflow/examples/simple_linear_listening.py7
-rw-r--r--taskflow/examples/wbe_event_sender.py4
4 files changed, 22 insertions, 12 deletions
diff --git a/doc/source/notifications.rst b/doc/source/notifications.rst
index 3fd35e2..c0dbe4e 100644
--- a/doc/source/notifications.rst
+++ b/doc/source/notifications.rst
@@ -7,6 +7,8 @@ Notifications and listeners
from taskflow import task
from taskflow.patterns import linear_flow
from taskflow import engines
+ from taskflow.types import notifier
+ ANY = notifier.Notifier.ANY
--------
Overview
@@ -57,7 +59,7 @@ A basic example is:
>>> flo = linear_flow.Flow("cat-dog").add(
... CatTalk(), DogTalk(provides="dog"))
>>> eng = engines.load(flo, store={'meow': 'meow', 'woof': 'woof'})
- >>> eng.notifier.register("*", flow_transition)
+ >>> eng.notifier.register(ANY, flow_transition)
>>> eng.run()
Flow 'cat-dog' transition to state RUNNING
meow
@@ -93,7 +95,7 @@ A basic example is:
>>> flo.add(CatTalk(), DogTalk(provides="dog"))
<taskflow.patterns.linear_flow.Flow object at 0x...>
>>> eng = engines.load(flo, store={'meow': 'meow', 'woof': 'woof'})
- >>> eng.task_notifier.register("*", task_transition)
+ >>> eng.task_notifier.register(ANY, task_transition)
>>> eng.run()
Task 'CatTalk' transition to state RUNNING
meow
diff --git a/taskflow/examples/build_a_car.py b/taskflow/examples/build_a_car.py
index 1655f2a..02be020 100644
--- a/taskflow/examples/build_a_car.py
+++ b/taskflow/examples/build_a_car.py
@@ -31,6 +31,9 @@ import taskflow.engines
from taskflow.patterns import graph_flow as gf
from taskflow.patterns import linear_flow as lf
from taskflow import task
+from taskflow.types import notifier
+
+ANY = notifier.Notifier.ANY
import example_utils as eu # noqa
@@ -160,11 +163,11 @@ spec = {
engine = taskflow.engines.load(flow, store={'spec': spec.copy()})
-# This registers all (*) state transitions to trigger a call to the flow_watch
-# function for flow state transitions, and registers the same all (*) state
-# transitions for task state transitions.
-engine.notifier.register('*', flow_watch)
-engine.task_notifier.register('*', task_watch)
+# This registers all (ANY) state transitions to trigger a call to the
+# flow_watch function for flow state transitions, and registers the
+# same all (ANY) state transitions for task state transitions.
+engine.notifier.register(ANY, flow_watch)
+engine.task_notifier.register(ANY, task_watch)
eu.print_wrapped("Building a car")
engine.run()
@@ -176,8 +179,8 @@ engine.run()
spec['doors'] = 5
engine = taskflow.engines.load(flow, store={'spec': spec.copy()})
-engine.notifier.register('*', flow_watch)
-engine.task_notifier.register('*', task_watch)
+engine.notifier.register(ANY, flow_watch)
+engine.task_notifier.register(ANY, task_watch)
eu.print_wrapped("Building a wrong car that doesn't match specification")
try:
diff --git a/taskflow/examples/simple_linear_listening.py b/taskflow/examples/simple_linear_listening.py
index 04f9f14..d14c82c 100644
--- a/taskflow/examples/simple_linear_listening.py
+++ b/taskflow/examples/simple_linear_listening.py
@@ -28,6 +28,9 @@ sys.path.insert(0, top_dir)
import taskflow.engines
from taskflow.patterns import linear_flow as lf
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
# 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)
# 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.
-engine.notifier.register('*', flow_watch)
-engine.task_notifier.register('*', task_watch)
+engine.notifier.register(ANY, flow_watch)
+engine.task_notifier.register(ANY, task_watch)
# And now run!
engine.run()
diff --git a/taskflow/examples/wbe_event_sender.py b/taskflow/examples/wbe_event_sender.py
index 38b6bfd..e5b075a 100644
--- a/taskflow/examples/wbe_event_sender.py
+++ b/taskflow/examples/wbe_event_sender.py
@@ -34,6 +34,8 @@ from taskflow import task
from taskflow.types import notifier
from taskflow.utils import threading_utils
+ANY = notifier.Notifier.ANY
+
# INTRO: This examples shows how to use a remote workers event notification
# attribute to proxy back task event notifications to the controlling process.
#
@@ -94,7 +96,7 @@ WORKER_CONF = {
def run(engine_options):
reporter = EventReporter()
- reporter.notifier.register(notifier.Notifier.ANY, event_receiver)
+ reporter.notifier.register(ANY, event_receiver)
flow = lf.Flow('event-reporter').add(reporter)
eng = engines.load(flow, engine='worker-based', **engine_options)
eng.run()