def task(ctx, config): """ Loop a sequential group of tasks example:: - loop: count: 10 body: - tasktest: - tasktest: :param ctx: Context :param config: Configuration """ for i in range(config.get('count', 1)): stack = [] try: for entry in config.get('body', []): if not isinstance(entry, dict): entry = ctx.config.get(entry, {}) ((taskname, confg), ) = entry.items() log.info('In sequential, running task %s...' % taskname) mgr = run_tasks.run_one_task(taskname, ctx=ctx, config=confg) if hasattr(mgr, '__enter__'): mgr.__enter__() stack.append(mgr) finally: try: exc_info = sys.exc_info() while stack: mgr = stack.pop() mgr.__exit__(*exc_info) finally: del exc_info
def task(ctx, config): """ Run a set of tasks to completion in order. __exit__ is called on a task before __enter__ on the next example:: - full_sequential: - tasktest: - tasktest: :param ctx: Context :param config: Configuration """ for entry in config: if not isinstance(entry, dict): entry = ctx.config.get(entry, {}) ((taskname, confg),) = entry.iteritems() log.info('In full_sequential, running task %s...' % taskname) mgr = run_tasks.run_one_task(taskname, ctx=ctx, config=confg) if hasattr(mgr, '__enter__'): try: mgr.__enter__() finally: try: exc_info = sys.exc_info() mgr.__exit__(*exc_info) finally: del exc_info
def task(ctx, config): """ Loop a sequential group of tasks example:: - loop: count: 10 body: - tasktest: - tasktest: :param ctx: Context :param config: Configuration """ for i in range(config.get('count', 1)): stack = [] try: for entry in config.get('body', []): if not isinstance(entry, dict): entry = ctx.config.get(entry, {}) ((taskname, confg),) = entry.iteritems() log.info('In sequential, running task %s...' % taskname) mgr = run_tasks.run_one_task(taskname, ctx=ctx, config=confg) if hasattr(mgr, '__enter__'): mgr.__enter__() stack.append(mgr) finally: try: exc_info = sys.exc_info() while stack: mgr = stack.pop() mgr.__exit__(*exc_info) finally: del exc_info
def task(ctx, config): """ Run a set of tasks to completion in order. __exit__ is called on a task before __enter__ on the next example:: - full_sequential: - tasktest: - tasktest: :param ctx: Context :param config: Configuration """ for entry in config: if not isinstance(entry, dict): entry = ctx.config.get(entry, {}) ((taskname, confg), ) = entry.iteritems() log.info('In full_sequential, running task %s...' % taskname) mgr = run_tasks.run_one_task(taskname, ctx=ctx, config=confg) if hasattr(mgr, '__enter__'): try: mgr.__enter__() finally: try: exc_info = sys.exc_info() mgr.__exit__(*exc_info) finally: del exc_info
def _run_spawned(ctx,config,taskname): mgr = {} try: log.info('In parallel, running task %s...' % taskname) mgr = run_tasks.run_one_task(taskname, ctx=ctx, config=config) if hasattr(mgr, '__enter__'): mgr.__enter__() finally: exc_info = sys.exc_info() if hasattr(mgr, '__exit__'): mgr.__exit__(*exc_info) del exc_info
def task(ctx, config): """ Sequentialize a group of tasks into one executable block example:: - sequential: - tasktest: - tasktest: You can also reference the job from elsewhere:: foo: tasktest: tasks: - sequential: - tasktest: - foo - tasktest: That is, if the entry is not a dict, we will look it up in the top-level config. Sequential tasks and Parallel tasks can be nested. :param ctx: Context :param config: Configuration """ stack = [] try: for entry in config: if not isinstance(entry, dict): entry = ctx.config.get(entry, {}) ((taskname, confg), ) = entry.iteritems() log.info('In sequential, running task %s...' % taskname) mgr = run_tasks.run_one_task(taskname, ctx=ctx, config=confg) if hasattr(mgr, '__enter__'): mgr.__enter__() stack.append(mgr) finally: try: exc_info = sys.exc_info() while stack: mgr = stack.pop() mgr.__exit__(*exc_info) finally: del exc_info
def task(ctx, config): """ Sequentialize a group of tasks into one executable block example:: - sequential: - tasktest: - tasktest: You can also reference the job from elsewhere:: foo: tasktest: tasks: - sequential: - tasktest: - foo - tasktest: That is, if the entry is not a dict, we will look it up in the top-level config. Sequential tasks and Parallel tasks can be nested. :param ctx: Context :param config: Configuration """ stack = [] try: for entry in config: if not isinstance(entry, dict): entry = ctx.config.get(entry, {}) ((taskname, confg),) = entry.iteritems() log.info('In sequential, running task %s...' % taskname) mgr = run_tasks.run_one_task(taskname, ctx=ctx, config=confg) if hasattr(mgr, '__enter__'): mgr.__enter__() stack.append(mgr) finally: try: exc_info = sys.exc_info() while stack: mgr = stack.pop() mgr.__exit__(*exc_info) finally: del exc_info
def task(ctx, config): """ Sequentialize a group of tasks into one executable block, run on cleanup example:: tasks: - foo: - full_sequential_finally: - final1: - final2: - bar: - baz: The final1 and final2 tasks will run when full_sequentiall_finally is torn down, after the nested bar and baz tasks have run to completion, and right before the preceding foo task is torn down. This is useful if there are additional steps you want to interject in a job during the shutdown (instead of startup) phase. :param ctx: Context :param config: Configuration """ try: yield finally: for entry in config: if not isinstance(entry, dict): entry = ctx.config.get(entry, {}) ((taskname, confg), ) = entry.iteritems() log.info('In full_sequential_finally, running task %s...' % taskname) mgr = run_tasks.run_one_task(taskname, ctx=ctx, config=confg) if hasattr(mgr, '__enter__'): try: mgr.__enter__() finally: try: exc_info = sys.exc_info() mgr.__exit__(*exc_info) finally: del exc_info
def task(ctx, config): """ Sequentialize a group of tasks into one executable block, run on cleanup example:: tasks: - foo: - full_sequential_finally: - final1: - final2: - bar: - baz: The final1 and final2 tasks will run when full_sequentiall_finally is torn down, after the nested bar and baz tasks have run to completion, and right before the preceding foo task is torn down. This is useful if there are additional steps you want to interject in a job during the shutdown (instead of startup) phase. :param ctx: Context :param config: Configuration """ try: yield finally: for entry in config: if not isinstance(entry, dict): entry = ctx.config.get(entry, {}) ((taskname, confg),) = entry.iteritems() log.info('In full_sequential_finally, running task %s...' % taskname) mgr = run_tasks.run_one_task(taskname, ctx=ctx, config=confg) if hasattr(mgr, '__enter__'): try: mgr.__enter__() finally: try: exc_info = sys.exc_info() mgr.__exit__(*exc_info) finally: del exc_info