Exemplo n.º 1
0
 def test_for_each_empty_collection(self):
     values = []
     retry1 = retry.ForEach(values, 'r1', provides='x')
     flow = lf.Flow('flow-1', retry1).add(utils.ConditionalTask('t1'))
     engine = self._make_engine(flow)
     engine.storage.inject({'y': 1})
     self.assertRaisesRegexp(exc.NotFound, '^No elements left', engine.run)
Exemplo n.º 2
0
 def test_for_each_with_set(self):
     collection = set([3, 2, 5])
     retry1 = retry.ForEach(collection, 'r1', provides='x')
     flow = lf.Flow('flow-1', retry1).add(utils.FailingTaskWithOneArg('t1'))
     engine = self._make_engine(flow)
     with utils.CaptureListener(engine) as capturer:
         self.assertRaisesRegexp(RuntimeError, '^Woot', engine.run)
     expected = ['flow-1.f RUNNING',
                 'r1.r RUNNING',
                 'r1.r SUCCESS(2)',
                 't1.t RUNNING',
                 't1.t FAILURE(Failure: RuntimeError: Woot with 2)',
                 't1.t REVERTING',
                 't1.t REVERTED',
                 'r1.r RETRYING',
                 't1.t PENDING',
                 'r1.r RUNNING',
                 'r1.r SUCCESS(3)',
                 't1.t RUNNING',
                 't1.t FAILURE(Failure: RuntimeError: Woot with 3)',
                 't1.t REVERTING',
                 't1.t REVERTED',
                 'r1.r RETRYING',
                 't1.t PENDING',
                 'r1.r RUNNING',
                 'r1.r SUCCESS(5)',
                 't1.t RUNNING',
                 't1.t FAILURE(Failure: RuntimeError: Woot with 5)',
                 't1.t REVERTING',
                 't1.t REVERTED',
                 'r1.r REVERTING',
                 'r1.r REVERTED',
                 'flow-1.f REVERTED']
     self.assertItemsEqual(capturer.values, expected)
Exemplo n.º 3
0
    def test_for_each_with_set(self):
        collection = set([3, 2, 5])
        retry1 = retry.ForEach(collection, 'r1', provides='x')
        flow = lf.Flow('flow-1', retry1).add(utils.FailingTaskWithOneArg('t1'))
        engine = self._make_engine(flow)

        self.assertRaisesRegexp(RuntimeError, '^Woot', engine.run)
        expected = [
            u't1 reverted(Failure: RuntimeError: Woot with 3)',
            u't1 reverted(Failure: RuntimeError: Woot with 2)',
            u't1 reverted(Failure: RuntimeError: Woot with 5)'
        ]
        self.assertItemsEqual(self.values, expected)
Exemplo n.º 4
0
import taskflow.engines
from taskflow.patterns import linear_flow as linearflow
from taskflow import task, retry


class EchoTask(task.Task):
    def execute(self, *args, **kwargs):
        print(self.name)
        print(args)
        print(kwargs)


if __name__ == '__main__':
    flow = linearflow.Flow('f1').add(
        EchoTask('t1'),
        linearflow.Flow('f2',
                        retry=retry.ForEach(values=['a', 'b', 'c'],
                                            name='r1',
                                            provides='value')).add(
                                                EchoTask('t2'),
                                                EchoTask('t3',
                                                         requires='value')),
        EchoTask('t4'))

    # while True:
    engine = taskflow.engines.load(flow, store=dict())
    engine.run()