我已经把这个 twitter 机器人放在一起,它非常简单。从外部 API 收集一些数据,对其进行处理并将其发布出去。
我尝试了几种不同的方法来让机器人在一小时内发出推文,现在我有了这个:
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
知道如何解决这个问题吗?