简体   繁体   English

Heroku 计划任务每​​ 10 分钟运行一次,每小时计划一次

[英]Heroku scheduled task running every 10 minutes, scheduled once an hour

So I've just pushed my twitter bot to Heroku, and set to run every hour on the half hour with the Heroku scheduler addon.所以我刚刚将我的 twitter bot 推送到 Heroku,并设置为每半小时运行一次,使用 Heroku 调度程序插件。 However, for whatever reason it's running every 10 minutes instead.但是,无论出于何种原因,它都是每 10 分钟运行一次。 Is this a bug with the scheduler?这是调度程序的错误吗? Here's an excerpt of my logs from when the scheduler ran it successfully and then it tried to run it again ten minutes later:这是调度程序成功运行它时我的日志的摘录,然后它在十分钟后尝试再次运行它:

2013-01-30T19:30:20+00:00 heroku[scheduler.4875]: Starting process with command `python ff7ebooks.py`
2013-01-30T19:30:21+00:00 heroku[scheduler.4875]: State changed from starting to up
2013-01-30T19:30:24+00:00 heroku[scheduler.4875]: Process exited with status 0
2013-01-30T19:30:24+00:00 heroku[scheduler.4875]: State changed from up to complete
2013-01-30T19:34:34+00:00 heroku[web.1]: State changed from crashed to starting
2013-01-30T19:34:42+00:00 heroku[web.1]: Starting process with command `python ff7ebooks.py`
2013-01-30T19:34:44+00:00 heroku[web.1]: Process exited with status 0
2013-01-30T19:34:44+00:00 heroku[web.1]: State changed from starting to crashed

I can provide whatever info anyone needs to help me diagnose this issue.The [web.1] log messages repeat every couple of minutes.我可以提供任何人需要的任何信息来帮助我诊断这个问题。[web.1] 日志消息每隔几分钟重复一次。 I don't want to spam my followers.我不想向我的追随者发送垃圾邮件。

If anyone else has this issue, I figured it out.如果其他人有这个问题,我想通了。 I enabled the scheduler and then allocated 0 dynos, that way it only allocates a Heroku dyno when it is scheduled to run.我启用了调度程序,然后分配了 0 个 dyno,这样它只在计划运行时分配一个 Heroku dyno。 For some reason it was running my process continuously and (my assumption is that) Twitter only let it connect to a socket every few minutes which resulted in the sporadic tweeting.出于某种原因,它一直在运行我的进程,并且(我的假设是)Twitter 每隔几分钟就让它连接到一个套接字,这导致了零星的推文。

I would share with you the solution of a guy that have helped me with a one-off running script (like a python script that starts and then ends, and not keeps running).我想与您分享一个帮助我完成一次性运行脚本的人的解决方案(例如一个开始然后结束,而不是一直运行的 python 脚本)。

Any question let me know, and I will help you --> andreabalbo.com有任何问题请告诉我,我会帮助你 --> andreabalbo.com

Hi Andrea嗨安德里亚

I have also just created a random process-type in my Procfile:我还刚刚在我的 Procfile 中创建了一个随机进程类型:

tmp-process-type: command:test tmp 进程类型:命令:测试

I did not toggle on the process-type in the Heroku Dashboard.我没有在 Heroku 仪表板中切换进程类型。 After installing the Advanced Scheduler, I creating a trigger with command "tmp-process-type" that runs every minute.安装高级调度程序后,我使用每分钟运行一次的命令“tmp-process-type”创建触发器。 Looking at my logs I can see that every minute a process started with "command:test", confirming that the process-type in the Procfile is working.查看我的日志,我可以看到每分钟都有一个进程以“command:test”开始,确认 Procfile 中的进程类型正在工作。 I then toggled on the process-type in the Heroku Dashboard.然后我在 Heroku 仪表板中切换进程类型。 This showed up immediately in my logs:这立即出现在我的日志中:

Scaled to tmp-process-type@1:Free web@0:Free by user ...缩放到 tmp-process-type@1:Free web@0:Free by user ...

This is because after toggling, Heroku will spin up a normal dyno that it will try to keep up.这是因为在切换之后,Heroku 将启动一个正常的 dyno,它会尝试跟上。 Since your script is a task that ends, the dyno dies and Heroku will automatically restart it, causing your task to be run multiple times.由于您的脚本是一个结束的任务,因此 dyno 死亡,Heroku 将自动重新启动它,从而导致您的任务多次运行。

In summary, the following steps should solve your problem: 1. Toggle your process-type off (but leave it in the Procfile) 2. Install advanced-scheduler 3. Create a trigger (recurring or one-off) with command "tmp-process-type" 4. Look at your logs to see if anything weird shows up总之,以下步骤应该可以解决您的问题: 1. 关闭您的进程类型(但将其保留在 Procfile 中) 2. 安装高级调度程序 3. 使用命令“tmp-”创建一个触发器(重复或一次性) process-type” 4. 查看你的日志,看看是否有任何奇怪的东西出现

With kind regards, Oscar亲切的问候,奥斯卡

Fixed this problem by only one action at the end:最后只用一个动作就解决了这个问题:

  • I put the amount of workers to 0我把工人数量设为 0
  • then in the scheduler it is still put "python ELO_voetbal.py" and automatically starts a worker for that.然后在调度程序中它仍然放置“python ELO_voetbal.py”并为此自动启动一个工作程序。
  • so I did not use either advanced scheduler or placed "tmp-process-type" somewhere.所以我既没有使用高级调度程序,也没有在某处放置“tmp-process-type”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM