def list_tasks(pattern): """ Goal: return tasks list based on prefix/pattern Arguments: pattern: if not empty, the first two characters will be used to search the entity. """ ltask = [] prefix = "*" if pattern == '-*' else pattern suffix = '' if prefix.endswith('*'): prefix = prefix[:-1] suffix = '*' task_where_clauses = [] if has_ability(flask.g, '', ''): # super admin so no control on the prefix of searching criteria task_where_clauses.append(prefix) else: search_entity_expression = to_regex_format(prefix[:2]) # empty == all entities search_user_expression = prefix[2:5] search_remaining_expression = prefix[5:] filtered_entities = [ent for ent in flask.g.entities if is_regex_matched(ent, search_entity_expression)] for entity in filtered_entities: if has_ability(flask.g, 'train', entity): task_where_clauses.append(entity + search_user_expression + search_remaining_expression) else: continue if not task_where_clauses: abort(make_response(jsonify(message="insufficient credentials for tasks %s" % pattern), 403)) for clause in task_where_clauses: for task_key in task.scan_iter(redis, clause + suffix): task_id = task.id(task_key) info = task.info( redis, taskfile_dir, task_id, ["launched_time", "alloc_resource", "alloc_lgpu", "alloc_lcpu", "resource", "content", "status", "message", "type", "iterations", "priority"]) if info["alloc_lgpu"]: info["alloc_lgpu"] = info["alloc_lgpu"].split(",") if info["alloc_lcpu"]: info["alloc_lcpu"] = info["alloc_lcpu"].split(",") info["image"] = '-' info["model"] = '-' if info["content"]: content = json.loads(info["content"]) info["image"] = content["docker"]["image"] + ':' + content["docker"]["tag"] j = 0 while j < len(content["docker"]["command"]) - 1: if content["docker"]["command"][j] == "-m" or content["docker"]["command"][j] == "--model": info["model"] = content["docker"]["command"][j+1] break j = j+1 del info['content'] info['task_id'] = task_id ltask.append(info) return flask.jsonify(ltask)
def list_tasks(pattern): ltask = [] prefix = pattern suffix = '' if prefix.endswith('*'): prefix = prefix[:-1] suffix = '*' p = has_ability(flask.g, '', prefix) if p is False: abort(make_response(jsonify(message="insufficient credentials for " "list tasks starting with %s" % prefix[0:2]), 403)) elif p is not True: prefix = p for task_key in task.scan_iter(redis, prefix + suffix): task_id = task.id(task_key) info = task.info( redis, taskfile_dir, task_id, ["launched_time", "alloc_resource", "alloc_lgpu", "resource", "content", "status", "message", "type", "iterations", "priority"]) if info["content"] is not None and info["content"] != "": content = json.loads(info["content"]) info["image"] = content['docker']['image'] del info['content'] else: info["image"] = '-' info['task_id'] = task_id ltask.append(info) return flask.jsonify(ltask)
def list_tasks(pattern): ltask = [] for task_key in task.scan_iter(redis, pattern): task_id = task.id(task_key) info = task.info(redis, task_id, ["queued_time", "service", "content", "status", "message"]) content = json.loads(info["content"]) info["image"] = content['docker']['image'] del info['content'] info['task_id'] = task_id ltask.append(info) return flask.jsonify(ltask)
def list_tasks(pattern): ltask = [] for task_key in task.scan_iter(redis, pattern): task_id = task.id(task_key) info = task.info(redis, task_id, [ "queued_time", "alloc_resource", "alloc_lgpu", "resource", "content", "status", "message", "type", "iterations", "priority" ]) if info["content"] is not None and info["content"] != "": content = json.loads(info["content"]) info["image"] = content['docker']['image'] del info['content'] else: info["image"] = '-' info['task_id'] = task_id ltask.append(info) return flask.jsonify(ltask)
def list_tasks(pattern): ltask = [] prefix = pattern suffix = '' if prefix.endswith('*'): prefix = prefix[:-1] suffix = '*' p = has_ability(flask.g, '', prefix) if p is False: abort( make_response( jsonify(message="insufficient credentials for " "list tasks starting with %s" % prefix[0:2]), 403)) elif p is not True: prefix = p for task_key in task.scan_iter(redis, prefix + suffix): task_id = task.id(task_key) info = task.info(redis, taskfile_dir, task_id, [ "launched_time", "alloc_resource", "alloc_lgpu", "alloc_lcpu", "resource", "content", "status", "message", "type", "iterations", "priority" ]) if info["alloc_lgpu"]: info["alloc_lgpu"] = info["alloc_lgpu"].split(",") if info["alloc_lcpu"]: info["alloc_lcpu"] = info["alloc_lcpu"].split(",") info["image"] = '-' info["model"] = '-' if info["content"]: content = json.loads(info["content"]) info["image"] = content["docker"]["image"] + ':' + content[ "docker"]["tag"] j = 0 while j < len(content["docker"]["command"]) - 1: if content["docker"]["command"][j] == "-m" or content[ "docker"]["command"][j] == "--model": info["model"] = content["docker"]["command"][j + 1] break j = j + 1 del info['content'] info['task_id'] = task_id ltask.append(info) return flask.jsonify(ltask)