コード例 #1
0
def getJobDesc():
    baseInfo = {}
    serviceJobDesc = ServiceJobDesc()
    try:
        page = request.args.get("page")
    except Exception as e:
        page = None

    try:
        limit = request.args.get("limit")
    except Exception as e:
        limit = None

    params = getRequestParams(request)
    try:
        baseInfo["success"] = True
        baseInfo["msg"] = "dataReturnSuccess"
        results = serviceJobDesc.getAll(params=params, page=page, limit=limit)
        return jsonify(dict(list(baseInfo.items()) +
                            list(results.items()))), 200
    except Exception as e:
        baseInfo["success"] = False
        baseInfo["msg"] = "dataReturnFailure"
        app.logger.info("ERROR:jobdescqueryapi.getJobDesc():" +
                        e.args.__str__())
        return jsonify(dict(list(baseInfo.items()))), 403
コード例 #2
0
def deleteCronTask():
    params = getRequestParams(request=request)
    try:
        app.dpScheduler.remove_job(params["jobId"])
        serviceJob = ServiceJob()
        serviceJob.deleteJob(jobId=params["jobId"])
        return jsonify({"success": True, "msg": "cronJobDeleteSuccessful"})
    except Exception as e:
        app.logger.info("ERROR:deleteCronTask:" + e.args.__str__())
        return jsonify({"success": False, "msg": "cronJobdeleteFailure"}), 305
コード例 #3
0
def resumeCronTask():
    params = getRequestParams(request=request)
    try:
        app.dpScheduler.resume_job(job_id=params["jobId"])
        job = app.dpScheduler.get_job(params["jobId"])
        serviceJob = ServiceJob()
        cronJob = serviceJob.getByJobId(params["jobId"])
        cronJob.jobStatus = job.__unicode__()
        cronJob.nextRunTime = job.next_run_time
        serviceJob.putJob(job=cronJob)
        return jsonify({"success": True, "msg": "cronJobResumeSuccessful"})
    except Exception as e:
        app.logger.info("ERROR:pauseCronTask:" + e.args.__str__())
        return jsonify({"success": False, "msg": "cronJobResumeFailure"}), 305
コード例 #4
0
def updateCronTask():
    params = getRequestParams(request=request)

    if params["triggerType"] == "Interval":
        try:
            trigger = IntervalTrigger(seconds=int(params["triggerParam"]))
        except Exception as e:
            app.logger.info("ERROR:taskqueryapi:updateCronTask()" +
                            e.args.__str__())
            return jsonify({"success": False, "msg": "jobParamTypeError"}), 305

    if params["triggerType"] == "Cron":
        triggerParams = params["triggerParam"].split("#")

        try:
            trigger = CronTrigger(minute=triggerParams[0],
                                  hour=triggerParams[1],
                                  day=triggerParams[2],
                                  month=triggerParams[3],
                                  day_of_week=triggerParams[4])
        except Exception as e:
            app.logger.info("ERROR:taskqueryapi:updateCronTask()" +
                            e.args.__str__())
            return jsonify({"success": False, "msg": "jobParamTypeError"}), 305
    try:
        app.dpScheduler.modify_job(job_id=params["jobId"],
                                   trigger=trigger,
                                   next_run_time=None,
                                   args=[
                                       dict([
                                           ["host", params["targetHost"]],
                                           ["jobParams", params["jobParams"]],
                                       ])
                                   ])
        app.dpScheduler.resume_job(job_id=params["jobId"])
        job = app.dpScheduler.get_job(params["jobId"])
        serviceJob = ServiceJob()
        cronJob = serviceJob.getByJobId(params["jobId"])
        cronJob.triggerType = params["triggerType"]
        cronJob.triggerParam = params["triggerParam"]
        cronJob.jobParams = params["jobParams"]
        cronJob.targetHost = params["targetHost"]
        cronJob.jobStatus = job.__unicode__()
        cronJob.nextRunTime = job.next_run_time
        serviceJob.putJob(job=cronJob)
        return jsonify({"success": True, "msg": "cronJobUpdateSuccessful"})
    except Exception as e:
        app.logger.info("ERROR:pauseCronTask:" + e.args.__str__())
        return jsonify({"success": False, "msg": "cronJobUpdateFailure"}), 305
コード例 #5
0
def getCronTaskByJobId():
    baseInfo = {}
    params = getRequestParams(request)
    serviceJob = ServiceJob()

    try:
        results = serviceJob.getAll(params, page=None, limit=None)
        baseInfo["success"] = True
        baseInfo["msg"] = "dataReturnSuccess"
        return jsonify(dict(list(baseInfo.items()) +
                            list(results.items()))), 200
    except Exception as e:
        baseInfo["success"] = False
        baseInfo["msg"] = "dataReturnFailure"
        app.logger.info(e.args.__str__())
        return jsonify(dict(list(baseInfo.items()) +
                            list(results.items()))), 403
コード例 #6
0
def putCronTask():
    params = getRequestParams(request=request)
    if params["triggerType"] == "Interval":
        try:
            trigger = IntervalTrigger(seconds=int(params["triggerParam"]))
        except Exception as e:
            return jsonify({"success": False, "msg": "jobParamTypeError"}), 305

    if params["triggerType"] == "Cron":
        triggerParams = params["triggerParam"].split("#")
        try:
            trigger = CronTrigger(minute=triggerParams[0],
                                  hour=triggerParams[1],
                                  day=triggerParams[2],
                                  month=triggerParams[3],
                                  day_of_week=triggerParams[4])
        except Exception as e:
            app.logger.info("ERROR:taskqueryapi:putCronTask()" +
                            e.args.__str__())
            return jsonify({"success": False, "msg": "jobParamTypeError"}), 305

    try:

        job = CronJob(jobName=params["jobName"],
                      triggerType=params["triggerType"],
                      triggerParam=params["triggerParam"],
                      jobParams=params["jobParams"],
                      targetHost=params["targetHost"],
                      func=params["jobName"])
        cronJob = app.dpScheduler.add_job(
            eval(job.jobName),
            trigger=trigger,
            args=[
                dict([
                    ["host", params["targetHost"]],
                    ["jobParams", params["jobParams"]],
                ])
            ])
        job.jobId = cronJob.id
        serviceJob = ServiceJob()
        serviceJob.putJob(job=job)
        return jsonify({"success": True, "msg": "cronJobAddSuccessful"})
    except Exception as e:
        app.logger.info("ERROR:putCronTask:" + e.args.__str__())
        return jsonify({"success": False, "msg": "cronJobAddFailure"}), 305