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)
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)
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))
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)
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)
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)