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'})
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'})
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'})
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'})
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
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
def _get_crontab(crontab_id): c = Crontab.get(crontab_id) if not c: abort(404) return c
def _get_crontab(crontab_id): c = Crontab.get(crontab_id) if not c: abort(404) return c