appname = os.path.basename(__file__) logger = logging.getLogger(appname) def prog(progname, success=True): logger = logging.getLogger(os.getenv("SEQUENT_LOGGER_NAME")) logger.info("doing what %s is doing" % progname) if not success: raise Exception("%s failed" % progname) return progname class StepResource(rp.Resource): pass rp1=rp.ResourcePool('RP1', resource_cls=StepResource, policy={'resource_limit': 2, }).load() myflow=seq.Sequent(name=appname, config={'sleep_between_loops': 0.05, 'LOGGING': {'logging_level': logging.INFO, }}, ) s1=myflow.add_step('s1', repeats=range(2) ) s11=s1.add_step('s11', repeats=[1,2,]) s111=s11.add_step('s111', func=prog, kwargs={'progname': 'prog1'}, acquires=[(rp1, 1), ]) s112=s11.add_step('s112', func=prog, kwargs={'progname': 'prog2',}, acquires=[(rp1, 1), ], requires=( (s111, seq.STEP_SUCCESS), )) s12=s1.add_step('s12', func=prog, kwargs={'progname': 'prog3'}, requires=( (s11, seq.STEP_SUCCESS), )) s2=myflow.add_step('s2', func=prog, kwargs={'progname': 'prog4'},
ev00first = ev.add_event('s0_00_start') ev00next = ev.add_event('s0_s00_next') ev00end = ev.add_event('s0_s00_end') ev1s = ev.add_event('s0_s00_s1_start') ev1success = ev.add_event('s0_s00_s1_success') ev2s = ev.add_event('s0_s00_s2_start', expr=(ev1success, )) ev2success = ev.add_event('s0_s00_s2_success') ev3s = ev.add_event('s0_s00_s3_start', expr=(ev2success, )) class StepResource(rp.Resource): pass rp1o = rp.ResourcePool('RP1', resource_cls=StepResource, policy={'resource_limit': 2}) rp1 = rp1o.load() rp2o = rp.ResourcePool('RP2', resource_cls=StepResource, policy={'resource_limit': 2}) rp2 = rp2o.load() metaprog1 = Container(progname='s0', loop=[1, 2], max_concurrent=2, iter_triggers=(ev00first, ), end_triggers=(ev0end, )) s0first = ev.add_step('s0_start', func=metaprog1, kwargs={'initial': True},
handler = create_stream_handler(logging_level=logging.DEBUG) logger.addHandler(handler) logger.setLevel(logging.INFO) class MyResource1(rp.Resource): pass class MyResource2(rp.Resource): pass rp1 = rp.ResourcePool('RP1', resource_cls=MyResource1, policy={ 'resource_limit': 2, }).load() rp2 = rp.ResourcePool('RP2', resource_cls=MyResource2, policy={ 'resource_limit': 2, }).load() class Callback(object): def __init__(self, notify_queue, name=''): self.q = notify_queue self.name = name def __call__(self, received=False):
def build_flow(run_mode=sqnt.RUN_RESTART, step_to_fail=None, iteration_to_fail='', run_id=None): myflow = sqnt.Sequent( name=appname, run_mode=run_mode, run_id=run_id, config={ 'sleep_between_loops': 0.05, 'LOGGING': { 'logging_level': logging.INFO, } }, ) rp1 = vrp.ResourcePool('rp1', resource_cls=Resources1, policy={ 'resource_limit': 4, }) rp2 = vrp.ResourcePool('rp2', resource_cls=Resources2, policy={ 'resource_limit': 4, }) s1 = myflow.add_step('s1', repeats=[1, 2], acquires=[ (rp1, 2), ]) s11 = s1.add_step('s11', repeats=[ 1, 2, ], acquires=[ (rp2, 2), ]) s111 = s11.add_step('s111', func=prog, kwargs={ 'progname': 'prog1', 'step_to_fail': step_to_fail, 'iteration_to_fail': iteration_to_fail, }) s112 = s11.add_step('s112', func=prog, kwargs={ 'progname': 'prog2', 'step_to_fail': step_to_fail, 'iteration_to_fail': iteration_to_fail, }, requires=((s111, sqnt.STEP_SUCCESS), )) s12 = s1.add_step('s12', func=prog, kwargs={ 'progname': 'prog3', 'step_to_fail': step_to_fail, 'iteration_to_fail': iteration_to_fail, }, requires=((s11, sqnt.STEP_SUCCESS), )) s2 = myflow.add_step('s2', func=prog, kwargs={ 'progname': 'prog4', 'step_to_fail': step_to_fail, 'iteration_to_fail': iteration_to_fail, }, requires=((s1, sqnt.STEP_SUCCESS), )) return myflow