logger.exception("Task %s failed due to error: %s" % (self.get_log_tag(), e)) completion_callback(self, TaskStatus.TASK_FAILED, reason="Got error: %s" % e) return 1 except Exception, e: logger.exception("Task %s failed due to exception: %s(%s)" % (self.get_log_tag(), e.__class__.__name__, e)) completion_callback(self, TaskStatus.TASK_FAILED, reason="Got exception: %s" % e) return 1 completion_callback(self, TaskStatus.TASK_SUCCESSFUL) return 0 task.register_task_type(StartWorker) class StopWorker(task.GenericTask): NAME="StopWorker" def __init__(self, job_id, name, worker_node, server_config): task.GenericTask.__init__(self, job_id, name, worker_node, server_config) self.zmq_job = None def get_description(self): return "Stopping worker at %s" % self.worker_node["name"] def start(self, status_update_callback, completion_callback): child = threading.Thread(target=self, args=(status_update_callback, completion_callback))
def __call__(self, msg_data, completion_callback): msg = message.parse_message(msg_data, "task_result") logger.debug("[%s] Got command task result: %s rc=%s logfile=%s" % (self.get_log_tag(), msg.status, msg.rc, msg.logfile)) if msg.output: for line in msg.output: logger.info("[%s] %s" % (self.worker_node["name"], line.rstrip())) if not msg.comment: reason = "Return code was %s, Logfile is at %s" % \ (msg.rc, msg.logfile) else: reason = msg.comment completion_callback(self, msg.status, reason=reason) task.register_task_type(Command) class CopyFiles(task.GenericTask): NAME="CopyFiles" def __init__(self, job_id, name, worker_node, server_config, src_path, dest_path): task.GenericTask.__init__(self, job_id, name, worker_node, server_config) self.src_path = src_path self.dest_path = dest_path def get_description(self): return "Copy %s to %s:%s" % (self.src_path, self.worker_node["name"], self.dest_path) def start(self, status_update_callback, completion_callback): child = threading.Thread(target=self, args=(status_update_callback, completion_callback))