//#import jobs.js
//#import $owl_tasks:services/modelService.jsx

function main() {

    var params = JSON.parse($body);
    var taskId = params.id;
    if (!taskId) {
        out.print(JSON.stringify({state: "err", msg: "参数错误"}));
        return;
    }

    var jTask = owl_tasksService.get(taskId);
    if (!jTask) {
        out.print(JSON.stringify({state: "err", msg: "任务不存在"}));
        return;
    }
    if (jTask.state == "running") {
        out.print(JSON.stringify({state: "err", msg: "当前任务正在执行，请等待本次执行完毕后再提交"}));
        return;
    }
    var jParams = JSON.parse(jTask.params || "{}");
    jParams.taskId = jTask.id;
    jParams.taskVid = jTask._v;

    var curTime = new Date().getTime();
    JobsService.submitTask(jTask.appId, jTask.pageId, jParams, curTime);

    out.print(JSON.stringify({state: "ok", msg: "操作成功"}));
}

main();