Ejemplo n.º 1
0
 def test_subworkflows_processes(self):
     sub = LocalWorkflow(TWorkflow)
     main = LocalWorkflow(W)
     main.conf_workflow('m', sub)
     main.conf_workflow('r', sub)
     result = main.run(8, r=True, _wait=True)
     self.assertEquals(result, 45)
Ejemplo n.º 2
0
 def test_activities_threads(self):
     try:
         from futures import ThreadPoolExecutor
     except ImportError:
         from concurrent.futures import ThreadPoolExecutor
     main = LocalWorkflow(W, executor=ThreadPoolExecutor)
     main.conf_activity('m', tactivity)
     main.conf_activity('r', tactivity)
     result = main.run(8, r=True, _wait=True)
     self.assertEquals(result, 45)
Ejemplo n.º 3
0
 def test_activities_threads(self):
     try:
         from futures import ThreadPoolExecutor
     except ImportError:
         from concurrent.futures import ThreadPoolExecutor
     main = LocalWorkflow(W, executor=ThreadPoolExecutor)
     main.conf_activity('m', tactivity)
     main.conf_activity('r', tactivity)
     result = main.run(8, r=True, _wait=True)
     self.assertEquals(result, 45)
Ejemplo n.º 4
0
 def test_subworkflows_threads(self):
     try:
         from futures import ThreadPoolExecutor
     except ImportError:
         from concurrent.futures import ThreadPoolExecutor
     sub = LocalWorkflow(TWorkflow)
     main = LocalWorkflow(W, executor=ThreadPoolExecutor)
     main.conf_workflow('m', sub)
     main.conf_workflow('r', sub)
     result = main.run(8, r=True, _wait=True)
     self.assertEquals(result, 45)
Ejemplo n.º 5
0
 def test_selfsubworkflows_processes(self):
     sub = LocalWorkflow(W, executor=ThreadPoolExecutor)
     sub.conf_activity('m', tactivity)
     sub.conf_activity('r', tactivity)
     main = LocalWorkflow(W)
     main.conf_workflow('m', sub)
     main.conf_activity('r', tactivity)
     result = main.run(8, r=True, _wait=True)
     self.assertEquals(result, 165)
Ejemplo n.º 6
0
 def test_subworkflows_processes(self):
     sub = LocalWorkflow(TWorkflow)
     main = LocalWorkflow(W)
     main.conf_workflow('m', sub)
     main.conf_workflow('r', sub)
     result = main.run(8, r=True, _wait=True)
     self.assertEquals(result, 45)
Ejemplo n.º 7
0
def main():
    # logging, the basicConfig is for futures, setup_default_logger is for flowy
    logging.basicConfig()
    setup_default_logger()

    def workflow(workflow_class):
        try:
            return globals()[workflow_class]
        except KeyError:
            raise ValueError('Workflow "%s" not found.' % workflow_class)

    parser = argparse.ArgumentParser(description='Example workflow runner.')
    parser.add_argument('workflow', action='store', type=workflow)
    parser.add_argument('--pure', action='store_true', default=False)
    parser.add_argument('--workflow-workers',
                        action='store',
                        type=int,
                        default=2)
    parser.add_argument('--activity-workers',
                        action='store',
                        type=int,
                        default=8)
    parser.add_argument('--timeit', action='store_true', default=False)
    parser.add_argument('--trace', action='store_true', default=False)
    parser.add_argument('--wait-children', action='store_true', default=False)
    args = parser.parse_args()

    start = time.time()
    if args.pure:
        wf = args.workflow(activity)
        result = wf()
    else:
        lw = LocalWorkflow(args.workflow,
                           activity_workers=args.activity_workers,
                           workflow_workers=args.workflow_workers)
        lw.conf_activity('a', activity)
        result = lw.run(_wait=args.wait_children, _trace=args.trace)
    if args.timeit:
        print('Timed at:', time.time() - start)
    print('Result:', result)
Ejemplo n.º 8
0
def main():
    # logging, the basicConfig is for futures, setup_default_logger is for flowy
    logging.basicConfig()
    setup_default_logger()

    def workflow(workflow_class):
        try:
            return globals()[workflow_class]
        except KeyError:
            raise ValueError('Workflow "%s" not found.' % workflow_class)

    parser = argparse.ArgumentParser(description='Example workflow runner.')
    parser.add_argument('workflow', action='store', type=workflow)
    parser.add_argument('--pure', action='store_true', default=False)
    parser.add_argument('--workflow-workers',
                        action='store',
                        type=int,
                        default=2)
    parser.add_argument('--activity-workers',
                        action='store',
                        type=int,
                        default=8)
    parser.add_argument('--timeit', action='store_true', default=False)
    parser.add_argument('--trace', action='store_true', default=False)
    parser.add_argument('--wait-children', action='store_true', default=False)
    args = parser.parse_args()

    start = time.time()
    if args.pure:
        wf = args.workflow(activity)
        result = wf()
    else:
        lw = LocalWorkflow(args.workflow,
                           activity_workers=args.activity_workers,
                           workflow_workers=args.workflow_workers)
        lw.conf_activity('a', activity)
        result = lw.run(_wait=args.wait_children, _trace=args.trace)
    if args.timeit:
        print('Timed at:', time.time() - start)
    print('Result:', result)
Ejemplo n.º 9
0
 def test(self):
     lw = LocalWorkflow(wf,
                        activity_workers=16,
                        workflow_workers=2,
                        executor=ThreadPoolExecutor)
     lw.conf_activity('a', examples.activity)
     start = time.time()
     result = lw.run(TIME_SCALE)
     duration = time.time() - start
     lines = [l.strip() for l in wf.__doc__.split("\n")]
     expected = None
     for line in lines:
         if line.startswith('R '):
             expected = int(line.split()[-1].split("-")[-1])
             break
     self.assertEquals(expected, result)
     for line in lines:
         if line.startswith('Duration:'):
             expected_duration = int(line.split()[-1]) * TIME_SCALE * 0.1
             break
     print(expected_duration, duration)
     self.assertTrue(abs(expected_duration - duration) < TIME_SCALE * 0.9)
Ejemplo n.º 10
0
 def test(self):
     lw = LocalWorkflow(wf,
                        activity_workers=16,
                        workflow_workers=2,
                        executor=ThreadPoolExecutor)
     lw.conf_activity('a', examples.activity)
     start = time.time()
     result = lw.run(TIME_SCALE)
     duration = time.time() - start
     lines = [l.strip() for l in wf.__doc__.split("\n")]
     expected = None
     for line in lines:
         if line.startswith('R '):
             expected = int(line.split()[-1].split("-")[-1])
             break
     self.assertEquals(expected, result)
     for line in lines:
         if line.startswith('Duration:'):
             expected_duration = int(line.split()[-1]) * TIME_SCALE * 0.1
             break
     print(expected_duration, duration)
     self.assertTrue(abs(expected_duration - duration) < TIME_SCALE * 0.9)
Ejemplo n.º 11
0
 def test_subworkflows_threads(self):
     try:
         from futures import ThreadPoolExecutor
     except ImportError:
         from concurrent.futures import ThreadPoolExecutor
     sub = LocalWorkflow(TWorkflow)
     main = LocalWorkflow(W, executor=ThreadPoolExecutor)
     main.conf_workflow('m', sub)
     main.conf_workflow('r', sub)
     result = main.run(8, r=True, _wait=True)
     self.assertEquals(result, 45)
Ejemplo n.º 12
0
 def test_activities_processes(self):
     main = LocalWorkflow(W)
     main.conf_activity('m', tactivity)
     main.conf_activity('r', tactivity)
     result = main.run(8, _wait=True)  # avoid broken pipe
     self.assertEquals(result, 45)
Ejemplo n.º 13
0
 def test_fail_subworkflow(self):
     main = LocalWorkflow(F)
     sub = LocalWorkflow(TWorkflow)
     main.conf_workflow('task', sub)
     self.assertRaises(TaskError, lambda: main.run(_wait=True))
     main = LocalWorkflow(F)
     main.conf_workflow('task', sub)
     self.assertRaises(TaskError, lambda: main.run(r=1, _wait=True))
     main = LocalWorkflow(F)
     main.conf_workflow('task', sub)
     self.assertRaises(TaskError, lambda: main.run(r=4, _wait=True))
     main = LocalWorkflow(F)
     main.conf_workflow('task', sub)
     self.assertRaises(TaskError, lambda: main.run(throw=True, _wait=True))
Ejemplo n.º 14
0
 def test_fail_activity(self):
     main = LocalWorkflow(F)
     main.conf_activity('task', tactivity)
     self.assertRaises(TaskError, lambda: main.run(_wait=True))
     main = LocalWorkflow(F)
     main.conf_activity('task', tactivity)
     self.assertRaises(TaskError, lambda: main.run(r=1, _wait=True))
     main = LocalWorkflow(F)
     main.conf_activity('task', tactivity)
     self.assertRaises(TaskError, lambda: main.run(r=4, _wait=True))
     main = LocalWorkflow(F)
     main.conf_activity('task', tactivity)
     self.assertRaises(TaskError, lambda: main.run(throw=True, _wait=True))
Ejemplo n.º 15
0
 def test_activities_processes(self):
     main = LocalWorkflow(W)
     main.conf_activity('m', tactivity)
     main.conf_activity('r', tactivity)
     result = main.run(8, _wait=True)  # avoid broken pipe
     self.assertEquals(result, 45)
Ejemplo n.º 16
0
 def test_fail_subworkflow(self):
     main = LocalWorkflow(F)
     sub = LocalWorkflow(TWorkflow)
     main.conf_workflow('task', sub)
     self.assertRaises(TaskError, lambda: main.run(_wait=True))
     main = LocalWorkflow(F)
     main.conf_workflow('task', sub)
     self.assertRaises(TaskError, lambda: main.run(r=1, _wait=True))
     main = LocalWorkflow(F)
     main.conf_workflow('task', sub)
     self.assertRaises(TaskError, lambda: main.run(r=4, _wait=True))
     main = LocalWorkflow(F)
     main.conf_workflow('task', sub)
     self.assertRaises(TaskError, lambda: main.run(throw=True, _wait=True))
Ejemplo n.º 17
0
 def test_fail_activity(self):
     main = LocalWorkflow(F)
     main.conf_activity('task', tactivity)
     self.assertRaises(TaskError, lambda: main.run(_wait=True))
     main = LocalWorkflow(F)
     main.conf_activity('task', tactivity)
     self.assertRaises(TaskError, lambda: main.run(r=1, _wait=True))
     main = LocalWorkflow(F)
     main.conf_activity('task', tactivity)
     self.assertRaises(TaskError, lambda: main.run(r=4, _wait=True))
     main = LocalWorkflow(F)
     main.conf_activity('task', tactivity)
     self.assertRaises(TaskError, lambda: main.run(throw=True, _wait=True))
Ejemplo n.º 18
0
 def test_selfsubworkflows_processes(self):
     sub = LocalWorkflow(W, executor=ThreadPoolExecutor)
     sub.conf_activity('m', tactivity)
     sub.conf_activity('r', tactivity)
     main = LocalWorkflow(W)
     main.conf_workflow('m', sub)
     main.conf_activity('r', tactivity)
     result = main.run(8, r=True, _wait=True)
     self.assertEquals(result, 165)