如何在 Heroku 上安排 python 脚本

How to schedule a python script on Heroku

我正在 Heroku 上部署一个脚本(一个 Scrapy python 脚本),我希望它在早上启动 4 次。

我绝对可以 运行 通过连接到我的 Heroku 帐户(我有一个免费计划)并在 windows 命令行中输入:

heroku run scrapy crawl sytadin

但是当我尝试通过 Heroku Scheduler 运行 它时遇到了一些问题。它问我是否要写类似 $ rake 的内容。 我以前没用过rake,是用在run之前还是在run之后? 我应该先使用关键字 heroku 吗?

我不知道,我尝试的一切都失败了,正如我在日志中看到的那样:

2017-01-19T23:47:05.305039+00:00 heroku[scheduler.3450]: Starting process with command `python "sytadin" crawl`
2017-01-19T23:47:05.974030+00:00 heroku[scheduler.3450]: State changed from starting to up
2017-01-19T23:47:08.335845+00:00 heroku[scheduler.3450]: State changed from up to complete
2017-01-19T23:47:08.204289+00:00 app[scheduler.3450]: /app/.heroku/python/bin/python: can't find '__main__' module in 'sytadin'
2017-01-19T23:47:08.326081+00:00 heroku[scheduler.3450]: Process exited with status 1
2017-01-19T23:48:27.681890+00:00 app[api]: Starting process with command `python sytadin/sytadin.py crawl` by user scheduler@addons.heroku.com
2017-01-19T23:48:35.571615+00:00 heroku[scheduler.6352]: Starting process with command `python sytadin/sytadin.py crawl`
2017-01-19T23:48:36.156250+00:00 heroku[scheduler.6352]: State changed from starting to up
2017-01-19T23:48:37.424920+00:00 heroku[scheduler.6352]: Process exited with status 2
2017-01-19T23:48:37.360306+00:00 app[scheduler.6352]: python: can't open file 'sytadin/sytadin.py': [Errno 2] No such file or directory
2017-01-19T23:48:37.445476+00:00 heroku[scheduler.6352]: State changed from up to complete

如您所见,我尝试了在网上找到的各种可能性,但都无法正常工作:(

有人猜我的 python 脚本吗? :)

Heroku 调度程序基本上只是执行 heroku run + 你在那里输入的任何命令。

因此,在您的情况下,由于您的 scrapy 爬虫成功 运行s 当您执行以下操作时:heroku run scrapy crawl sytadin,您可以创建调度程序规则以 运行:

scrapy crawl sytadin

这样就可以了 =)