def run_and_print(self, args, **kwargs): instance = self.run(args, **kwargs) if not instance: raise Exception("Server did not create instance.") parent_id = instance.execution_id stream_mgr = self.app.client.managers["Stream"] execution = None with term.TaskIndicator() as indicator: events = ["st2.execution__create", "st2.execution__update"] for event in stream_mgr.listen( events, end_execution_id=parent_id, end_event="st2.execution__update", **kwargs, ): execution = Execution(**event) if (execution.id == parent_id and execution.status in LIVEACTION_COMPLETED_STATES): break # Suppress intermediate output in case output formatter is requested if args.json or args.yaml: continue if getattr(execution, "parent", None) == parent_id: status = execution.status name = (execution.context["orquesta"]["task_name"] if "orquesta" in execution.context else execution.context["chain"]["name"]) if status == LIVEACTION_STATUS_SCHEDULED: indicator.add_stage(status, name) if status == LIVEACTION_STATUS_RUNNING: indicator.update_stage(status, name) if status in LIVEACTION_COMPLETED_STATES: indicator.finish_stage(status, name) if execution and execution.status == LIVEACTION_STATUS_FAILED: args.depth = 1 self._print_execution_details(execution=execution, args=args, **kwargs) sys.exit(1) return self.app.client.managers["Execution"].get_by_id( parent_id, **kwargs)
def run_and_print(self, args, **kwargs): instance = self.run(args, **kwargs) if not instance: raise Exception('Server did not create instance.') parent_id = instance.execution_id stream_mgr = self.app.client.managers['Stream'] execution = None with term.TaskIndicator() as indicator: events = ['st2.execution__create', 'st2.execution__update'] for event in stream_mgr.listen(events, **kwargs): execution = Execution(**event) if execution.id == parent_id \ and execution.status in LIVEACTION_COMPLETED_STATES: break # Suppress intermediate output in case output formatter is requested if args.json or args.yaml: continue if getattr(execution, 'parent', None) == parent_id: status = execution.status name = execution.context['orquesta']['task_name'] \ if 'orquesta' in execution.context else execution.context['chain']['name'] if status == LIVEACTION_STATUS_SCHEDULED: indicator.add_stage(status, name) if status == LIVEACTION_STATUS_RUNNING: indicator.update_stage(status, name) if status in LIVEACTION_COMPLETED_STATES: indicator.finish_stage(status, name) if execution and execution.status == LIVEACTION_STATUS_FAILED: args.depth = 1 self._print_execution_details(execution=execution, args=args, **kwargs) sys.exit(1) return self.app.client.managers['Execution'].get_by_id( parent_id, **kwargs)