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

标签 python heroku schedule

我正在 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/

相关文章:

java - 尝试安排 TimerTask 时出现语法错误

python - 设置 matplotlib 颜色栏范围

java - 部署在heroku中的Spring Boot应用程序中的外部Jars

python - 当尝试设置运行计划时,类立即调用方法。函数没有发生

python - 在 Heroku 上安装 PyODBC 时找不到 sql.h

php - Yii2 Url::remember() 是如何工作的?

java - 用于 Java 的通用分布式调度库

python - 无法点击分页中的下一个按钮

python - 如何返回仅具有 iloc[1,1] 颜色样式和字体样式的特定单元格?

python - 使用 pandas 从字符串矩阵构造计数矩阵(整数)的方法(Python)