def _start_heartbeat(self, heartbeat_type, flow_id, run_id, step_name=None, task_id=None): if self._already_started(): # A single ServiceMetadataProvider instance can not start # multiple heartbeat side cars of any type/combination. Either a # single run heartbeat or a single task heartbeat can be started raise Exception("heartbeat already started") # start sidecar if self.version() is None or \ LooseVersion(self.version()) < LooseVersion('2.0.4'): # if old version of the service is running # then avoid running real heartbeat sidecar process self.sidecar_process = SidecarSubProcess("nullSidecarHeartbeat") else: self.sidecar_process = SidecarSubProcess("heartbeat") # create init message payload = {} if heartbeat_type == HeartbeatTypes.TASK: # create task heartbeat data = { 'flow_id': flow_id, 'run_number': run_id, 'step_name': step_name, 'task_id': task_id, } payload[HB_URL_KEY] = self.mli_url_task_template.format(**data) elif heartbeat_type == HeartbeatTypes.RUN: # create run heartbeat data = {'flow_id': flow_id, 'run_number': run_id} payload[HB_URL_KEY] = self.mli_url_run_template.format(**data) else: raise Exception("invalid heartbeat type") payload["service_version"] = self.version() msg = Message(MessageTypes.LOG_EVENT, payload) self.sidecar_process.msg_handler(msg)
def stop_heartbeat(self): msg = Message(MessageTypes.SHUTDOWN, None) self.sidecar_process.msg_handler(msg)