Increase persistence example comments
Change-Id: Ibd137ea7017bdf248e6ea524cfa7e5b39f4ad37f
This commit is contained in:
@@ -39,6 +39,23 @@ from taskflow.utils import persistence_utils as p_utils
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
|
# INTRO: In this example we create two tasks, one that will say hi and one
|
||||||
|
# that will say bye with optional capability to raise an error while
|
||||||
|
# executing. During execution if a later task fails, the reverting that will
|
||||||
|
# occur in the hi task will undo this (in a ~funny~ way).
|
||||||
|
#
|
||||||
|
# To also show the effect of task persistence we create a temporary database
|
||||||
|
# that will track the state transitions of this hi + bye workflow, this
|
||||||
|
# persistence allows for you to examine what is stored (using a sqlite client)
|
||||||
|
# as well as shows you what happens during reversion and what happens to
|
||||||
|
# the database during both of these modes (failing or not failing).
|
||||||
|
|
||||||
|
def print_wrapped(text):
|
||||||
|
print("-" * (len(text)))
|
||||||
|
print(text)
|
||||||
|
print("-" * (len(text)))
|
||||||
|
|
||||||
|
|
||||||
class HiTask(task.Task):
|
class HiTask(task.Task):
|
||||||
def execute(self):
|
def execute(self):
|
||||||
print("Hi!")
|
print("Hi!")
|
||||||
@@ -58,18 +75,16 @@ class ByeTask(task.Task):
|
|||||||
print("Bye!")
|
print("Bye!")
|
||||||
|
|
||||||
|
|
||||||
|
# This generates your flow structure (at this stage nothing is ran).
|
||||||
def make_flow(blowup=False):
|
def make_flow(blowup=False):
|
||||||
flo = lf.Flow("hello-world")
|
flo = lf.Flow("hello-world")
|
||||||
flo.add(HiTask(), ByeTask(blowup))
|
flo.add(HiTask(), ByeTask(blowup))
|
||||||
return flo
|
return flo
|
||||||
|
|
||||||
|
|
||||||
def print_wrapped(text):
|
# Persist the flow and task state here, if the file exists already blowup
|
||||||
print("-" * (len(text)))
|
# if not don't blowup, this allows a user to see both the modes and to
|
||||||
print(text)
|
# see what is stored in each case.
|
||||||
print("-" * (len(text)))
|
|
||||||
|
|
||||||
|
|
||||||
persist_filename = os.path.join(tempfile.gettempdir(), "persisting.db")
|
persist_filename = os.path.join(tempfile.gettempdir(), "persisting.db")
|
||||||
if os.path.isfile(persist_filename):
|
if os.path.isfile(persist_filename):
|
||||||
blowup = False
|
blowup = False
|
||||||
@@ -105,6 +120,9 @@ try:
|
|||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
|
# NOTE(harlowja): don't exit with non-zero status code, so that we can
|
||||||
|
# print the book contents, as well as avoiding exiting also makes the
|
||||||
|
# unit tests (which also runs these examples) pass.
|
||||||
traceback.print_exc(file=sys.stdout)
|
traceback.print_exc(file=sys.stdout)
|
||||||
|
|
||||||
print_wrapped("Book contents")
|
print_wrapped("Book contents")
|
||||||
|
|||||||
Reference in New Issue
Block a user