Heroku+Django:每15分钟重启一次dyno



我有一个Django网站托管在Heroku上。我需要重新启动1 dyno";时钟";(我的crontab APScheduler(,每15分钟一次。

通过Heroku CLI,可以通过以下命令行完成:

heroku dyno:restart clock.1

但我似乎无法在Django应用程序中实现自动化。

我已经尝试使用我的crontab APScheduler来重新启动自己:

  1. 创建名为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它会工作

  1. 通过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命令行?

这应该会帮助您并回答您的问题:如何在Django 中设置cron作业

最新更新