gpt4 book ai didi

python - 如何在 Heroku 上安排 python 脚本

转载 作者:太空狗 更新时间:2023-10-30 00:34:35 26 4
gpt4 key购买 nike

我正在 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 爬虫在您执行以下操作时成功运行:heroku run scrapy crawl sytadin,您可以创建一个调度程序规则来运行:

scrapy crawl sytadin

这样就可以了 =)

关于python - 如何在 Heroku 上安排 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41753804/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com