def _on_task_done(self, task): """Task callback. Args: task (asyncio.task.Task): """ with Action.continue_task(task_id=self._context['eliot_task']): self.logger.debug(f"Task done: {self.name}") self._tm.unregister_task(self)
def with_eliot(action_type, master_id=None, worker_id=None): assert master_id or worker_id if worker_id: # print "WITH {}".format(worker_id) master_id = RedisWorker(worker_id).master.master_id master = RedisMaster(master_id) eliot_task_id = master.eliot_task_id del Logger._destinations._destinations[:] to_file(open(eliot_log_path + master_id, "ab")) with Action.continue_task(task_id=eliot_task_id): return start_action(action_type=action_type)
def elioterize(action_type, master_id=None, worker_id=None): """Eliot action continuer that can log to either worker or master.""" clear_logger_destinations(Logger) if worker_id: to_file(get_eliot_log_file(worker_id=worker_id)) client = RedisWorker(worker_id) elif master_id: to_file(get_eliot_log_file(master_id=master_id)) client = RedisMaster(master_id) with Action.continue_task(task_id=client.eliot_task_id): return start_action(action_type=action_type)
def logger(self, request, **routeArguments): serialized_remote_task = request.requestHeaders.getRawHeaders("X-Eliot-Task-Id", [None])[0] if serialized_remote_task is None: return original(self, request, **routeArguments) try: action = Action.continue_task(task_id=serialized_remote_task) except ValueError: return original(self, request, **routeArguments) with action.context(): d = DeferredContext(original(self, request, **routeArguments)) d.addActionFinish() return d.result
def logger(self, request, **routeArguments): serialized_remote_task = request.requestHeaders.getRawHeaders( "X-Eliot-Task-Id", [None])[0] if serialized_remote_task is None: return original(self, request, **routeArguments) try: action = Action.continue_task(task_id=serialized_remote_task) except ValueError: return original(self, request, **routeArguments) with action.context(): d = DeferredContext(original(self, request, **routeArguments)) d.addActionFinish() return d.result
def thread_start(task_id): # Since loading the image metadata is done separately from # booting the node, it's possible the metadata here won't # actually match the metadata of the image the node ends up # running (someone could replace the image with a different one # between this call and the node being started). Since # generating images is currently a manual step, this probably # won't happen very often and if it does there's a person there # who can deal with it. Also it will be resolved after the # next node restart. It would be better to extract the image # metadata from the booted node, though. # FLOC-1905 with Action.continue_task(task_id=task_id): self.image_metadata = self.driver.get_image_metadata() return self.driver.create()
def wrapper(*args, **kwargs): redis_worker = Session.session.config.option.redis_worker eliot_task_id = redis_worker.eliot_task_id # print "~{} {}".format(eliot_task_id, action_type) del Logger._destinations._destinations[:] to_file(open(os.path.join(eliot_log_path, redis_worker.master.uuid + '.' + redis_worker.task_id), "ab")) eliot_task = Action.continue_task(task_id=eliot_task_id) with eliot_task: with start_action(action_type=action_type, worker_id=redis_worker.task_id, **dec_kwargs): func(*args, **kwargs) redis_worker.eliot_task_id = eliot_task.serialize_task_id()
def wrapped(*args, **kwargs): task_id = kwargs.get("task_id") if task_id: action = Action.continue_task(task_id=task_id) else: action = start_action(action_type=name) with action.context(): task_id = action.serialize_task_id() kwargs["task_id"] = task_id if with_state: kwargs["state_manager"] = StateManager(name) try: return f(*args, **kwargs) except Exception as e: logging.exception(f"Error during the execution of {f}: <{e}>") action.finish()
def wrapper(*args, **kwargs): redis_worker = Session.session.config.option.redis_worker eliot_task_id = redis_worker.eliot_task_id # print "~{} {}".format(eliot_task_id, action_type) del Logger._destinations._destinations[:] to_file( open( os.path.join( eliot_log_path, redis_worker.master.uuid + '.' + redis_worker.task_id), "ab")) eliot_task = Action.continue_task(task_id=eliot_task_id) with eliot_task: with start_action(action_type=action_type, worker_id=redis_worker.task_id, **dec_kwargs): func(*args, **kwargs) redis_worker.eliot_task_id = eliot_task.serialize_task_id()
def run(self): with Action.continue_task(task_id=self.task_id): try: with open(self.settings_file, "r") as fd: global_settings = json.load(fd) logging_settings = global_settings.get("logging") live_settings = global_settings.get("live") logging.setup_python_logging(logging_settings) logging.setup_live_logging(logging_settings, live_settings) agent_processes = processes.start(global_settings) except KeyboardInterrupt: logging.info("Execution interrupted") raise except Exception: logging.exception("Error processing inputs") raise for item in agent_processes: item.terminate() item.join()
def fromStringProto(self, inString, proto): return Action.continue_task( proto.logger, Unicode.fromStringProto(self, inString, proto))
def main(): with Action.continue_task(task_id=request.headers["x-eliot-task-id"]): x = int(request.args["x"]) y = int(request.args["y"]) return str(divide(x, y))
def main(): with Action.continue_task(logger, request.headers["x-eliot-task-id"]): x = int(request.args["x"]) y = int(request.args["y"]) return str(divide(x, y))
def second_task(action_id): Message.log(action_id=action_id) with Action.continue_task(task_id=action_id): Message.log(action_id=action_id, ty=str(type(action_id)))