def set_state(self, state, state_info, processed=None): """Sets task state without executing post completion logic. :param state: New task state. :param state_info: New state information (i.e. error message). :param processed: New "processed" flag value. :return: True if the state was changed as a result of this call, False otherwise. """ assert self.task_ex cur_state = self.task_ex.state if cur_state != state or self.task_ex.state_info != state_info: task_ex = db_api.update_task_execution_state(id=self.task_ex.id, cur_state=cur_state, state=state) if task_ex is None: # Do nothing because the update query did not change the DB. return False self.task_ex = task_ex self.task_ex.state_info = json.dumps(state_info) \ if isinstance(state_info, dict) else state_info self.state_changed = True # Recalculating "started_at" timestamp only if the state # was WAITING (all preconditions are satisfied and it's # ready to start) or IDLE, or the task is being rerun. So # we treat all iterations of "retry" policy as one run. if state == states.RUNNING and \ (cur_state in (None, states.WAITING) or self.rerun): self.task_ex.started_at = utils.utc_now_sec() if states.is_completed(state): self.task_ex.finished_at = utils.utc_now_sec() if self.rerun: self.task_ex.finished_at = None if processed is not None: self.task_ex.processed = processed self._notify(cur_state, state) wf_trace.info( self.task_ex.workflow_execution, "Task '%s' (%s) [%s -> %s, msg=%s]" % (self.task_ex.name, self.task_ex.id, cur_state, state, self.task_ex.state_info)) return True
def set_state(self, state, state_info, processed=None): """Sets task state without executing post completion logic. :param state: New task state. :param state_info: New state information (i.e. error message). :param processed: New "processed" flag value. :return: True if the state was changed as a result of this call, False otherwise. """ assert self.task_ex cur_state = self.task_ex.state # Set initial started_at in case of waiting => running. # We can't set this just in run_existing, because task retries # will update started_at, which is incorrect. if cur_state == states.WAITING and state == states.RUNNING: self.save_started_time() if cur_state != state or self.task_ex.state_info != state_info: task_ex = db_api.update_task_execution_state( id=self.task_ex.id, cur_state=cur_state, state=state ) if task_ex is None: # Do nothing because the update query did not change the DB. return False self.task_ex = task_ex self.task_ex.state_info = json.dumps(state_info) \ if isinstance(state_info, dict) else state_info self.state_changed = True if processed is not None: self.task_ex.processed = processed wf_trace.info( self.task_ex.workflow_execution, "Task '%s' (%s) [%s -> %s, msg=%s]" % (self.task_ex.name, self.task_ex.id, cur_state, state, self.task_ex.state_info) ) return True
def set_state(self, state, state_info, processed=None): """Sets task state without executing post completion logic. :param state: New task state. :param state_info: New state information (i.e. error message). :param processed: New "processed" flag value. :return: True if the state was changed as a result of this call, False otherwise. """ assert self.task_ex cur_state = self.task_ex.state # Set initial started_at in case of waiting => running. # We can't set this just in run_existing, because task retries # will update started_at, which is incorrect. if cur_state == states.WAITING and state == states.RUNNING: self.save_started_time() if cur_state != state or self.task_ex.state_info != state_info: task_ex = db_api.update_task_execution_state( id=self.task_ex.id, cur_state=cur_state, state=state ) if task_ex is None: # Do nothing because the update query did not change the DB. return False self.task_ex = task_ex self.task_ex.state_info = json.dumps(state_info) \ if isinstance(state_info, dict) else state_info self.state_changed = True if processed is not None: self.task_ex.processed = processed wf_trace.info( self.task_ex.workflow_execution, "Task '%s' (%s) [%s -> %s, msg=%s]" % (self.task_ex.name, self.task_ex.id, cur_state, state, self.task_ex.state_info) ) return True
def set_state(self, state, state_info, processed=None): """Sets task state without executing post completion logic. :param state: New task state. :param state_info: New state information (i.e. error message). :param processed: New "processed" flag value. :return: True if the state was changed as a result of this call, False otherwise. """ assert self.task_ex cur_state = self.task_ex.state if cur_state != state or self.task_ex.state_info != state_info: task_ex = db_api.update_task_execution_state( id=self.task_ex.id, cur_state=cur_state, state=state ) if task_ex is None: # Do nothing because the update query did not change the DB. return False self.task_ex = task_ex self.task_ex.state_info = json.dumps(state_info) \ if isinstance(state_info, dict) else state_info self.state_changed = True if processed is not None: self.task_ex.processed = processed wf_trace.info( self.task_ex.workflow_execution, "Task '%s' (%s) [%s -> %s, msg=%s]" % (self.task_ex.name, self.task_ex.id, cur_state, state, self.task_ex.state_info) ) return True
def set_state(self, state, state_info, processed=None): """Sets task state without executing post completion logic. :param state: New task state. :param state_info: New state information (i.e. error message). :param processed: New "processed" flag value. :return True if the state was changed as a result of this call, False otherwise. """ assert self.task_ex cur_state = self.task_ex.state if cur_state != state or self.task_ex.state_info != state_info: task_ex = db_api.update_task_execution_state( id=self.task_ex.id, cur_state=cur_state, state=state ) if task_ex is None: # Do nothing because the update query did not change the DB. return False self.task_ex = task_ex self.task_ex.state_info = state_info self.state_changed = True if processed is not None: self.task_ex.processed = processed wf_trace.info( self.task_ex.workflow_execution, "Task '%s' (%s) [%s -> %s, msg=%s]" % (self.task_ex.name, self.task_ex.id, cur_state, state, state_info) ) # Add kafka log trace task_input = None task_output = None actions = self.task_ex.action_executions if actions: if len(actions) > 1: actions = sorted(actions, key=lambda a : a.created_at, reverse=False) # klog.d("GET TASK action_executions", actions) task_input = actions[-1].input task_output = actions[-1].output atom_id = None if task_input and isinstance(task_input, dict) and task_input.has_key('atom'): atom_id = task_input['atom'] trigger = {} if 'triggered_by' in self.task_ex.runtime_context: trigger = self.task_ex.runtime_context['triggered_by'] kfk_trace.log(kfk_etypes.tk_parse(cur_state, state), atom_id, state, self.wf_ex.workflow_id, self.wf_ex.id, self.task_ex.id, self.task_ex.name, task_input, task_output, trigger) return True