Paste #445605

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from taskflow import task

from taskflow.patterns import linear_flow

import logging

logging.basicConfig(level=5)

from taskflow import engines
from taskflow.persistence import models

from taskflow.listeners import logging as logging_listener

from oslo_utils import uuidutils


class ProvidesThings(task.Task):

    default_provides = frozenset(['a'])

    def execute(self):
        print 'Running %s' % self.name
        return {
            'a': 2,
        }


class ExecutesThings(task.Task):
    def execute(self, *args, **kwargs):
        print 'Running %s' % self.name
        print args
        print kwargs

    
class MoreExecutesThings(task.Task):
    def execute(self, *args, **kwargs):
        print 'Running %s' % self.name
        print args
        print kwargs


stuff = linear_flow.Flow("stuff")
stuff.add(ProvidesThings(), ExecutesThings(requires=['a']))

flow_detail = models.FlowDetail("all-the-things", uuidutils.generate_uuid())

print "==== E1 ==="
e = engines.load(stuff, flow_detail=flow_detail)
e.compile()
with logging_listener.DynamicLoggingListener(e):
    e.run()
print e.storage.backend.memory.pformat()

print "==== E2 ==="
stuff.add(MoreExecutesThings(requires=['a']))
e2 = engines.load(stuff, backend=e.storage.backend, flow_detail=flow_detail)
e2.compile()
with logging_listener.DynamicLoggingListener(e2):
    e2.run()
print e2.storage.backend.memory.pformat()