我整理了这个推特机器人,它非常简单。从外部API收集一些数据,对其进行处理并将其推文发布。
我尝试了几种不同的方法来使Bot每小时鸣叫一次,现在我有了:
func main() {
fmt.Println("------ Starting bot ------")
func() {
for range time.Tick(time.Second) {
fmt.Println("checking for", time.Now().Format("15:04:05"))
if time.Now().Format("04") == "00" {
// call the function that calls the external API and does all the work
}
}
}()
}
可以确定可以进行一些改进,但是它在本地运行,因此我对此感到满意。问题是,当我在Heroku上部署它时,它运行了大约一分钟且不断变化。以下是日志:
2019-12-10T06:26:47.622145+00:00 app[web.1]: checking for 06:26:47
2019-12-10T06:26:48.622122+00:00 app[web.1]: checking for 06:26:48
2019-12-10T06:26:49.622554+00:00 app[web.1]: checking for 06:26:49
2019-12-10T06:26:50.622181+00:00 app[web.1]: checking for 06:26:50
2019-12-10T06:26:51.622207+00:00 app[web.1]: checking for 06:26:51
2019-12-10T06:26:52.622019+00:00 app[web.1]: checking for 06:26:52
2019-12-10T06:26:53.181083+00:00 heroku[web.1]: State changed from starting to crashed
2019-12-10T06:26:53.075003+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-12-10T06:26:53.075113+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-12-10T06:26:53.162250+00:00 heroku[web.1]: Process exited with status 137
任何想法如何解决这个问题?
最佳答案
评论中的答案更复杂。 Heroku具有运行状况检查系统,该系统会将请求发送到您的应用程序以检查其是否响应。如果您不会在60秒内打开端口,它将终止该应用程序。您可以在这里了解更多信息:https://devcenter.heroku.com/articles/dynos#web-dynos
关于go - Twitter机器人在Heroku中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59261507/