【发布时间】:2021-02-26 13:16:13
【问题描述】:
我有一个托管在 Heroku 上的 Django 网站。 我需要每 15 分钟重新启动 1 个测功机“时钟”(我的 crontab APScheduler)。
通过 Heroku CLI,这可以通过命令行来完成:
heroku dyno:restart clock.1
但我似乎无法从 Django 应用程序中自动化它。
我尝试使用我的 crontab APScheduler 自行重启:
- 创建一个名为 restart_clock 的管理命令
class Command(BaseCommand):
help = "Restarting dyno"
def handle(self, *args, **options):
os.system('heroku dyno:restart clock.1')
==> 如果我手动运行python manage.py restart_clock,它可以工作
- 通过 APScheduler 在 Heroku 上托管的应用程序中将其作为 crontab 运行
@sched.scheduled_job('cron',minute="*/10")
def restart():
os.system('python manage.py restart_clock')
sched.start()
然后,我收到一条消息错误
sh: 1: heroku: not found
感觉 Django 无法将 Heroku CLI 命令作为 cronjobs 运行...... 有没有办法每 15 分钟运行一次 Heroku CLI 命令行?
【问题讨论】: