def load_worker(worker_id): worker = ws.get_worker(worker_id) result = worker.__dict__ if worker.current_task_id: task = ats.get_task_by_id(worker.current_task_id) if task: result['is_assembling'] = True else: task = lts.get_task_by_id(worker.current_task_id) parents = ts.get_assembling_parents( worker.current_task_id) if result.get( 'is_assembling', False) else ts.get_learning_parents( worker.current_task_id) running_task_ids = [ t_id for t_id, t in parents if t.state == "running" ] result['task_ids'] = running_task_ids if len(running_task_ids) > 1: result['is_working_on_multiple_tasks'] = True result['log'] = task.log return result
def get_task(): worker = ws.get_worker(g.hash) ws.ping_worker(g.hash, worker) assigned_task_id, assigned_task = ws.assign_task_to_worker( g.hash, worker) return assigned_task or ''
def set_status(self, json): progress = max(.0, min(1., float(json['progress']))) message = str(json['message']) worker = ws.get_worker(g.hash) success = self.persist_status(ats, worker.current_task_id, progress, message) if not success: success = self.persist_status(lts, worker.current_task_id, progress, message) return success
def func_wrapper(*args, **kwargs): try: worker = ws.get_worker(request.json['hash']) if worker: g.worker = worker g.hash = request.json['hash'] return f(*args, **kwargs) except Exception as e: pass abort(400, message="Unknown worker id.") return None
def _stop_sub_task(sub_task_id, task_store, assembling): sub_task = task_store.get_task_by_id(sub_task_id) worker_id = sub_task.assigned_to parents = ts.get_assembling_parents(sub_task_id) if assembling else ts.get_learning_parents(sub_task_id) if not parents: return sub_task_changes = sub_task.stop() if sub_task_changes: task_store.update_task(sub_task_changes, sub_task_id) if not sub_task.assigned_to: worker = ws.get_worker(worker_id) if worker: worker_changes = worker.clear_task() ws.update_worker(worker_changes, worker_id)
def set_result(self, json): worker = ws.get_worker(g.hash) result = self.persist_result( "assembling", ats, worker.current_task_id, self.get_assemble_result, json['result'] ) or self.persist_result( "learning", lts, worker.current_task_id, self.get_learn_result, json['result'] ) if result: changes = worker.clear_task() success = ws.update_worker(changes, g.hash) if success: return result return False
def remove_current_task(worker_id, json): worker = ws.get_worker(g.hash) ws.ping_worker(g.hash, worker) return ws.worker_error(worker_id, worker, json['log'])
def fix_worker(worker_id): worker = ws.get_worker(worker_id) changes = worker.error_solved() return ws.update_worker(changes, worker_id)