示例#1
0
def re_cancel():
    jobs = scheduler.get_jobs()
    jobs_id = [(job.id, job.name) for job in jobs]
    if request.method == 'POST':
        job_id = request.form.get('cancel')
        scheduler.delete_job(job_id)  # delete the selected recurring job
        flash('Job deleted!', category='success')
        return redirect(url_for('views.home'))
    return render_template('re_cancel.html', user=current_user, jobs=jobs_id)
示例#2
0
 def get(self,id):
     task = Task.query.filter_by(id=id).first()
     try:
         scheduler.delete_job(str(id))
         task.yunxing_status=u'关闭'
         db.session.commit()
         flash(u'定时任务移除成功!')
         return redirect(url_for('home.timingtask'))
     except:
         task.yunxing_status = u'创建'
         db.session.commit()
         flash(u'定时任务移除失败!已经为您初始化')
         return redirect(url_for('home.timingtask'))
示例#3
0
def index():
    conn = sqlite3.connect('app.db')
    c = conn.cursor()

    if request.method == 'POST':
        look_for_data()
        scheduler.delete_job('job1')
        scheduler.add_job('job1', look_for_data, trigger='interval', seconds=Config.JOBS[0]['seconds'])

    response = []
    c.execute('SELECT * FROM activo WHERE descargar=? ORDER BY nombre', (1,))
    query = c.fetchall()
    for q in query:
        c.execute('SELECT * FROM cotizacion WHERE activo_id=? ORDER BY fecha DESC LIMIT 2', (q[0],))
        data = c.fetchall()
        if len(data) == 2:
            ticker = q[1]
            nombre = q[2]
            fechaultima = date_to_eu_format(data[0][1])
            VLultimo = data[0][2]
            VLanterior = data[1][2]
            variation = (VLultimo - VLanterior) / VLanterior * 100
            VLultimo = "{0:.4f}".format(VLultimo)
            VLanterior = "{0:.4f}".format(VLanterior)
            fechaanterior = date_to_eu_format(data[1][1])
            variation = "{0:.2f}".format(variation)
            activo_id = q[0]
        elif len(data) == 1:
            ticker = q[1]
            nombre = q[2]
            fechaultima = date_to_eu_format(data[0][1])
            VLultimo = data[0][2]
            VLanterior = ""
            variation = ""
            VLultimo = "{0:.4f}".format(VLultimo)
            fechaanterior = ""
            activo_id = q[0]
        response.append([ticker, nombre, fechaultima, VLultimo, fechaanterior, VLanterior, variation, activo_id])

    c.execute("SELECT * from variables WHERE name=?", ("last_scrape",))
    query = c.fetchone()
    if query is None:
        last_scrape = 0
    else:
        last_scrape = int(float(query[1]))
    next_run_time_epoch = scheduler.get_job('job1').next_run_time.timestamp()
    t_last = datetime.datetime.utcfromtimestamp(last_scrape)
    t_next = datetime.datetime.utcfromtimestamp(next_run_time_epoch)
    data = [t_last, t_next]

    return render_template('index.html', title='Home', table=response, data=data)
示例#4
0
    def post(self):
        """
        删除监控周期任务
        """
        args = self.parse_args(delete_scheduler_fields)
        job_id_list = args.get("job_id", [])

        ret_data = {"job_id": job_id_list}

        for job_id in job_id_list:
            item = app_scheduler.find_job(job_id)
            if not item:
                return utils.build_ret(ErrorMsg.JobNotFound, ret_data)

        for job_id in job_id_list:
            app_scheduler.delete_job(job_id)

        return utils.build_ret(ErrorMsg.Success, ret_data)
示例#5
0
 def delete_job(self):
     scheduler.delete_job(self.scheduler_id)