Example #1
0
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)
Example #2
0
 def saveWorkflowState(self):
     status = self.getStatus()
     taskstate = TaskState(self.taskData.id, self._pause, self.submitTime, self.startTime, self.finishedTime, self.getState(), self._outputDirId, self.taskData.name, self.taskData.flowId, self.wfData.name, status, self.formatError() if status=='Error' else '', self.userId)
     if self._taskStateId:
         TaskStateDao.modifyTaskState(self._taskStateId, taskstate, self.userId)
     else:
         self._taskStateId = TaskStateDao.addTaskState(taskstate)
     self.lastTaskState = TaskStateDao.lastTaskState(self.taskData.id, self.userId)
Example #3
0
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 []
        }]
    }
Example #4
0
def getTaskState(id):
    taskstate = TaskStateDao.lastTaskState(id, getUserId())
    if taskstate:
        clan = json.loads(taskstate.clan)
        if taskstate.endTime:
            runtime = taskstate.endTime - taskstate.startTime
        else:
            runtime = time.time() - taskstate.startTime
        clan['runTime'] = runtime
        return flask.jsonify(clan)
    else:
        return flask.jsonify({})
Example #5
0
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': []
        }]
    }