首页 > 解决方案 > 调度程序完成工作后,Heroku 不会将更改提交到 SQLAlchemy 数据库

问题描述

我在 heroku 上运行 Flask 应用程序并计划实现调度程序。一切似乎都在本地服务器上运行,但在 Heroku 上它从不向数据库提交更改。我在免费层上运行它。这是代码:

from app import app, db, SteamProfiles, hours_calculator
from apscheduler.schedulers.blocking import BlockingScheduler


def daily_users_update():
    for profile in SteamProfiles.query:
        clear_id = profile.steam_profile_id.replace("http://steamcommunity.com/profiles/", "")
        status, hours = hours_calculator(clear_id)
        profile.hours_in_2_weeks = hours
        print(profile.hours_in_2_weeks)
        db.session.commit()

scheduler = BlockingScheduler()
scheduler.add_job(daily_users_update, "interval", seconds=30)
scheduler.start()

如果我通过 heroku 终端运行它,我会看到它确实更新了小时数,但没有更新数据库。此外,运行时没有错误,只是执行日志。

这是过程文件:

web: gunicorn app:app

clock: python updater.py

不明白它有什么问题,所以任何建议都会非常感激。谢谢!

标签: flaskherokusqlalchemyscheduler

解决方案


推荐阅读