def queryTaskStatus(): userid = getUserId() flowid = flask.request.form.get('flowid') if not flowid: code = ErrorCode.NoFlowIdInReq return flask.jsonify({'code': code}) taskIdList = TaskDao.queryTaskIdByFlowId(flowid, userid) if taskIdList == []: code = ErrorCode.NotFindTaskByFlowId return flask.jsonify({'code': code}) taskstateList = [] message = {} for taskid in taskIdList: taskstate = TaskStateDao.lastTaskState(taskid, userid) if taskstate: taskstateList.append(taskstate) else: message[taskid] = 'NotRuning' for info in taskstateList: if info.endTime: message[info.taskId] = 'NotRuning' else: message[info.taskId] = 'Runing' return flask.jsonify(message)
def listTaskDir(userid, taskId, userId): task = TaskDao.queryTask(taskId, userId) if not task: return {'code': ErrorCode.NotFindTaskById} token = getTokenByuserid(userid) def _listDir(dirid): ret = [] dirs = listDir(token, dirid) for d in dirs: if d['type'] == 'dir': ret.append({ 'type': 'dir', 'path': d['path'], 'children': _listDir(d['id']) }) elif d['type'] == 'file': obj = {'type': 'file', 'path': d['path']} ft = checkFileType(d['path']) if ft == FileType.TIFF_FILE: obj['url'] = tiffserver.queryWMSUrl( d['metadataid'], userid) elif ft == FileType.SHP_FILE: obj['url'] = shpserver.queryWMSUrl(d['metadataid'], userid) else: obj['url'] = dataserver.getPreviewUrl(d['metadataid']) ret.append(obj) return ret dirs = listDir(token, task.dir) taskState = TaskStateDao.lastTaskState(taskId, userId) inputs = None outputs = None for d in dirs: if d['path'] == config.INPUT_DIR_NAME: inputs = _listDir(d['id']) elif taskState and str(d['id']) == taskState.fsId: outputs = _listDir(d['id']) return { 'code': ErrorCode.NoError, 'type': 'dir', 'path': task.name, 'children': [{ 'type': 'dir', 'path': config.INPUT_DIR_NAME, 'children': inputs or [] }, { 'type': 'dir', 'path': config.OUTPUT_DIR_NAME, 'children': outputs or [] }] }
def delWorkFlow(): userId = getUserId() # 删除流程 flowId = flask.request.form.get('id') if not flowId: return flask.jsonify({'code': ErrorCode.NoFlowIdInReq}) flow = WorkFlowDao.queryWorkflow(flowId, userId) if flow.userId != userId: return flask.jsonify({'code': ErrorCode.CannotDeleteMutualFlow}) UiDataDao.deleteUiDataByFlowId(flowId, userId) taskIdList = TaskDao.queryTaskIdByFlowId(flowId, userId) for id in taskIdList: TaskStateDao.deleteTaskState(id, userId) TaskDao.deleteByFlowId(flowId, userId) code = WorkFlowDao.deleteWorkflow(flowId, userId) return flask.jsonify({'code': code})
def addTask(): content = flask.request.form.get('content') if not content: return flask.jsonify({ 'code': ErrorCode.NoContentInReq, 'id': -1 }) taskId = flask.request.form.get('id') code = ErrorCode.NoError if taskId: code = TaskDao.updateTask(taskId, content, getUserId()) else: task = Task(content, getUserId()) code = TaskDao.saveTask(task) taskId = task.id return flask.jsonify({ 'code': code, 'id': taskId })
def deleteTask(): taskId = flask.request.form.get('id') if not taskId: return flask.jsonify({'code': ErrorCode.NoTaskIdInReq}) try: _requestTaskServerRetCode(taskId, TaskRequestType.StopTask) except: config.Log.info('can not kill module') TaskStateDao.deleteTaskState(taskId, getUserId()) code = TaskDao.deleteTask(taskId, getUserId()) try: lltsIdList = StateClanDao.delByTaskId(taskId, getUserId()) except: config.Log.info('can not kill module while delete task') return flask.jsonify({'code': code})
def startTask(): taskId = flask.request.form.get('id') if not taskId: return flask.jsonify({'code': ErrorCode.NoTaskIdInReq}) userId = getUserId() # userId = '200010035103900' task = TaskDao.queryTask(taskId, userId) if not task: return flask.jsonify({'code': ErrorCode.NotFindTaskById}) flow = WorkFlowDao.queryWorkflow(task.flowId, userId) if not flow: return flask.jsonify({'code': ErrorCode.NotFindFlowById}) return _requestTaskServerRetCode(taskId, TaskRequestType.StartTask, { 'task': task.dumpDetail(), 'flow': flow.dumpDetail() })
def listInputOutputDir(userid, taskId, userId): token = getTokenByuserid(userid) task = TaskDao.queryTask(taskId, userId) inputid = None outputid = None inputname = None outputname = None if not task: return {'code': ErrorCode.NotFindTaskById} dirs = listDir(userid, task.dir) taskState = TaskStateDao.lastTaskState(taskId, userId) for d in dirs: if d['path'] == config.INPUT_DIR_NAME: inputid = d['id'] inputname = d['path'] elif taskState and str(d['id']) == taskState.fsId: outputid = d['id'] outputname = d['path'] return { 'code': ErrorCode.NoError, 'type': 'dir', 'path': task.name, 'children': [{ 'type': 'dir', 'path': inputname, 'id': inputid, 'children': [] }, { 'type': 'dir', 'path': outputname, 'id': outputid, 'children': [] }] }
def taskDetail(id): task = TaskDao.queryTask(id, getUserId()) taskObj = task.dumpDetail() if task else {} return flask.jsonify(taskObj)
def taskList(): flowId = flask.request.args.get('flowId') if not flowId: return flask.jsonify({'code': ErrorCode.NoFlowIdInReq}) tasks = [task.dumpInfo() for task in TaskDao.taskList(getUserId(), flowId)] return flask.jsonify(tasks)