【发布时间】:2021-12-04 07:44:11
【问题描述】:
我正在尝试利用 APScheduler 定期检查数据库并在需要时发送电子邮件。不幸的是,每当我部署到 Heroku 时,我都会遇到同样的错误。当我在本地运行时,代码运行得非常好。
这是我的代码:
from flask_apscheduler import APScheduler, scheduler
#from pytz import timezone
#from sendgrid import SendGridAPIClient
#from sendgrid.helpers.mail import Mail
#from models import db, User, Applications, Tasks, Contact
#from datetime import datetime, timedelta
#from flask import current_app as app
sched = APScheduler()
def send_email():
print("Hello")
sched.add_job(id='Sending Email', func=send_email, trigger='interval', minutes = 1)
sched.start()
print("HelloTest")
我注释掉了大部分导入,只是为了测试时钟过程,不受其他模块的干扰。
我不断收到此错误:
2021-12-04T07:37:14.422436+00:00 heroku[clock.1]: Starting process with command `python /app/backend/clock.py`
2021-12-04T07:37:15.106399+00:00 heroku[clock.1]: State changed from starting to u
2021-12-04T07:37:16.801846+00:00 heroku[clock.1]: Process exited with status 0
2021-12-04T07:37:16.877624+00:00 heroku[clock.1]: State changed from up to crashed
2021-12-04T07:37:16.601432+00:00 app[clock.1]: /app/.heroku/python/lib/python3.9/site-packages/apscheduler/util.py:95: PytzUsageWarning: The zone attribute is specific to pytz's interface; please migrate to a new time zone provider. For more details on how to do so, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
2021-12-04T07:37:16.601448+00:00 app[clock.1]: if obj.zone == 'local':
2021-12-04T07:37:16.604340+00:00 app[clock.1]: /app/.heroku/python/lib/python3.9/site-packages/apscheduler/triggers/interval.py:66: PytzUsageWarning: The normalize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
2021-12-04T07:37:16.604342+00:00 app[clock.1]: return self.timezone.normalize(next_fire_time)
2021-12-04T07:37:16.610777+00:00 app[clock.1]: HelloTest
【问题讨论】:
-
您看到的是警告,而不是错误。究竟是什么导致了进程崩溃?
标签: flask heroku apscheduler