예제 #1
0
파일: ajax.py 프로젝트: tonicbupt/elegon
def on(crontab_id):
    crontab = Crontab.get(crontab_id)
    if not crontab:
        return jsonify({'r': 1, 'msg': 'not found'})
        
    if get_crontab(crontab):
        return jsonify({'r': 1, 'msg': 'already on'})

    add_crontab(crontab)
    return jsonify({'r': 0, 'msg': 'ok'})
예제 #2
0
파일: ajax.py 프로젝트: tonicbupt/elegon
def off(crontab_id):
    crontab = Crontab.get(crontab_id)
    if not crontab:
        return jsonify({'r': 1, 'msg': 'not found'})
        
    if not get_crontab(crontab):
        return jsonify({'r': 1, 'msg': 'already off'})

    remove_crontab(crontab)
    return jsonify({'r': 0, 'msg': 'ok'})
예제 #3
0
def off(crontab_id):
    crontab = Crontab.get(crontab_id)
    if not crontab:
        return jsonify({'r': 1, 'msg': 'not found'})

    if not get_crontab(crontab):
        return jsonify({'r': 1, 'msg': 'already off'})

    remove_crontab(crontab)
    return jsonify({'r': 0, 'msg': 'ok'})
예제 #4
0
def on(crontab_id):
    crontab = Crontab.get(crontab_id)
    if not crontab:
        return jsonify({'r': 1, 'msg': 'not found'})

    if get_crontab(crontab):
        return jsonify({'r': 1, 'msg': 'already on'})

    add_crontab(crontab)
    return jsonify({'r': 0, 'msg': 'ok'})
예제 #5
0
def run_crontab(crontab_id):
    crontab = Crontab.get(crontab_id)
    if not crontab:
        return

    # debug 打开并不真正执行任务.
    if CRONTAB_DEBUG:
        return

    props = crontab.props
    callback_url = url_for('crontab.callback',
                           crontab_id=crontab.id,
                           _external=True)
    try:
        r = eru.deploy_private(
            props.get('group', ''),
            props.get('pod', ''),
            props.get('appname', ''),
            1,
            1,
            props.get('version', ''),
            props.get('entrypoint', ''),
            props.get('env', ''),
            props.get('network_ids', []),
            callback_url=callback_url,
        )
    except EruException as e:
        print e
        return

    task_id = r['tasks'][0]
    while True:
        time.sleep(1)
        try:
            task = eru.get_task(task_id)
            if not task['finished']:
                continue

            container_id = task['props']['container_ids'][0]
            cronjob = CronJob.get_by_container_id(container_id)
            if not cronjob:
                crontab.add_job(container_id)

            break
        except EruException as e:
            print e
            break
예제 #6
0
def run_crontab(crontab_id):
    crontab = Crontab.get(crontab_id)
    if not crontab:
        return

    # debug 打开并不真正执行任务.
    if CRONTAB_DEBUG:
        return

    props = crontab.props
    callback_url = url_for('crontab.callback', crontab_id=crontab.id, _external=True)
    try:
        r = eru.deploy_private(
            props.get('group', ''),
            props.get('pod', ''),
            props.get('appname', ''),
            1,
            1,
            props.get('version', ''),
            props.get('entrypoint', ''),
            props.get('env', ''),
            props.get('network_ids', []),
            callback_url=callback_url,
        )
    except EruException as e:
        print e
        return

    task_id = r['tasks'][0]
    while True:
        time.sleep(1)
        try:
            task = eru.get_task(task_id)
            if not task['finished']:
                continue

            container_id = task['props']['container_ids'][0]
            cronjob = CronJob.get_by_container_id(container_id)
            if not cronjob:
                crontab.add_job(container_id)

            break
        except EruException as e:
            print e
            break
예제 #7
0
파일: crontab.py 프로젝트: tonicbupt/elegon
def _get_crontab(crontab_id):
    c = Crontab.get(crontab_id)
    if not c:
        abort(404)
    return c
예제 #8
0
def _get_crontab(crontab_id):
    c = Crontab.get(crontab_id)
    if not c:
        abort(404)
    return c