flask - 调度程序完成工作后,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
不明白它有什么问题,所以任何建议都会非常感激。谢谢!
解决方案
推荐阅读
- database - 系统设计问题
- c++ - CreateProcessAsUser 太快无法跟踪进程
- r - 用“0”和“1”替换列
- .htaccess - .htaccess 带参数的 RewriteRule 似乎不起作用
- isabelle - 是否有仅适用于命题逻辑的证明者
- php - 警告::C 中没有这样的文件或目录
- javascript - 动态加载页面时Django url标签不起作用
- android - Firebase 动态链接在第一次从 Play 商店安装后断开,并且在第一次安装后不打开深层链接
- python - 编写带有修饰函数和导入的模块
- javascript - 使用 Word Count 插件获取 TinyMCE 中的字数