Пример #1
0
def update_job_schedule(job_id):
    sched = get_scheduler()
    job_id = job_id.upper()
    job = sched.get_job(job_id)
    if not job:
        raise BadRequestError(f'No job found for job id: {job_id}')
    if request.method == 'DELETE':
        app.logger.warn(
            f'About to delete schedule definition for job id: {job_id}')
        sched.remove_job(job_id)
        return tolerant_jsonify([job_to_dict(job) for job in sched.get_jobs()])
    else:
        # If JSON properties are present, they will be evaluated by APScheduler's cron trigger API.
        # https://apscheduler.readthedocs.io/en/latest/modules/triggers/cron.html#module-apscheduler.triggers.cron
        try:
            args = request.get_json(force=True)
        except Exception as e:
            raise BadRequestError(str(e))
        if args:
            try:
                job.reschedule(trigger='cron', **args)
            except Exception as e:
                raise BadRequestError(f'Error rescheduling job: {e}')
        # Passing a empty JSON object will pause this job.
        else:
            job.pause()
        job = sched.get_job(job_id)
        return tolerant_jsonify(job_to_dict(job))
Пример #2
0
def update_scheduled_job_args(job_id):
    try:
        args = request.get_json(force=True)
    except Exception as e:
        raise BadRequestError(str(e))
    if not args:
        raise BadRequestError(f'Could not parse args from request')
    sched = get_scheduler()
    job_id = job_id.upper()
    job = sched.get_job(job_id)
    if not job:
        raise BadRequestError(f'No job found for job id: {job_id}')
    try:
        existing_args = job.args
        if len(existing_args) > 2:
            new_args = dict(existing_args[2])
            new_args.update(args)
        else:
            new_args = args
        job.modify(args=[existing_args[0], existing_args[1], new_args])
    except Exception as e:
        raise BadRequestError(f'Error updating job args: {e}')
    job = sched.get_job(job_id)
    return tolerant_jsonify(job_to_dict(job))
Пример #3
0
def get_job_schedule():
    sched = get_scheduler()
    return tolerant_jsonify([job_to_dict(job) for job in sched.get_jobs()])