def from_base_event(cls, event: BaseEvent) -> 'TaskSchedulingEvent': o = json.loads(event.value) return TaskSchedulingEvent(task_id=o['task_id'], dag_id=o['dag_id'], execution_date=dates.parse_execution_date( o['execution_date']), try_number=int(o['try_number']), action=SchedulingAction(o['action']))
def parse_configs(config_str: str): configs: List[MetConfig] = [] config_json = json.loads(config_str) for config in config_json: met_config = MetConfig(event_key=config['event_key'], event_value=config['event_value'], event_type=config['event_type'], action=SchedulingAction(config['action']), condition=MetCondition(config['condition']), value_condition=MetValueCondition(config['value_condition']), life=EventLife(config['life'])) configs.append(met_config) return configs
def _process_request_event(self, event: RequestEvent, session: Session = None): try: message = BaseUserDefineMessage() message.from_json(event.body) if message.message_type == UserDefineMessageType.RUN_DAG: # todo make sure dag file is parsed. dagrun = self._create_dag_run(message.dag_id, session=session, run_type=DagRunType.MANUAL) if not dagrun: self.log.error("Failed to create dag_run.") # TODO Need to add ret_code and errro_msg in ExecutionContext in case of exception self.notification_client.send_event( ResponseEvent(event.request_id, None).to_event()) return tasks = self._find_schedulable_tasks(dagrun, session, False) self._send_scheduling_task_events(tasks, SchedulingAction.START) self.notification_client.send_event( ResponseEvent(event.request_id, dagrun.run_id).to_event()) elif message.message_type == UserDefineMessageType.STOP_DAG_RUN: dag_run = DagRun.get_run_by_id(session=session, dag_id=message.dag_id, run_id=message.dagrun_id) self._stop_dag_run(dag_run) self.notification_client.send_event( ResponseEvent(event.request_id, dag_run.run_id).to_event()) elif message.message_type == UserDefineMessageType.EXECUTE_TASK: dagrun = DagRun.get_run_by_id(session=session, dag_id=message.dag_id, run_id=message.dagrun_id) ti: TI = dagrun.get_task_instance(task_id=message.task_id) self.mailbox.send_message( TaskSchedulingEvent(task_id=ti.task_id, dag_id=ti.dag_id, execution_date=ti.execution_date, try_number=ti.try_number, action=SchedulingAction( message.action)).to_event()) self.notification_client.send_event( ResponseEvent(event.request_id, dagrun.run_id).to_event()) except Exception: self.log.exception("Error occurred when processing request event.")
def from_base_event(cls, event: BaseEvent) -> 'EventHandleEvent': o = json.loads(event.value) return EventHandleEvent(task_id=o['task_id'], dag_run_id=o['dag_run_id'], dag_id=o['dag_id'], action=SchedulingAction(o['action']))