如何使用 Sinatra 应用程序在 Heroku 中运行 cron 作业
我正在编写一个小型 Sinatra 应用程序,为了简单起见,我想将其托管在 Heroku 上。但是,我的任务是每小时废弃一些网站并将一些数据添加到我的数据库中。目前这只是编写为需要执行的 ruby 脚本。 Heroku 拥有的是基于 rake 的 cron 作业。现在,如果这是一个 Rails 应用程序,我可以轻松地做到这一点,但我想避免像这样简单的事情带来的混乱。
有办法避免这种情况吗?或者我是否还必须在我的应用程序中安装 rake?
谢谢。
埃里克
I'm writing a tiny Sinatra app, and I want to host it on Heroku for simplicity sake. But, what I have is a task that scraps some sites and adds some data into my database every hour. Currently this is just written as a ruby script that needs to be executed. What Heroku has is a rake based cron job. Now if this was a rails app, I could easily do this, but I want to avoid the clutter for something as simple as this.
Is there a way to avoid this? Or do I have to install rake as well with my app?
Thank you.
Eric
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你需要一个像这样的 Rakefile:
Heroku 定期在你的应用程序中执行 rake cron,具体取决于你是否选择了“cron 附加组件”为每小时或每天。
You need a Rakefile like:
Heroku periodically executes rake cron in your app depending on whether you have selected the "cron add-on" to be hourly or daily.
你需要看看鲁弗斯。鲁弗斯是你的朋友。当您的应用程序加载时,Rufus 将成为您的 crontab。
我没有在 Heroku 上尝试过这个东西,但是,尝试一下并回复我们。
http://codex.heroku.com/past/2010/4/15/ rufus_scheduler_for_my_tiny_sinatra_apps/
为什么 Rufus 很酷?好吧,检查一下,它很干净:)
You need to check out Rufus. Rufus is your friend. Rufus will be your crontab while your app is loaded.
I did not try this stuff on Heroku but, give it a try and reply to us.
http://codex.heroku.com/past/2010/4/15/rufus_scheduler_for_my_tiny_sinatra_apps/
Why Rufus is cool? Well check this out, it's clean :)
又看了一遍,看来我这个问题太仓促了。
对于不是 Rails 的应用程序,只需创建一个
Rakefile
并将任务放在那里。希望这对其他人有帮助。
干杯!
Looked again and looks like I jumped the gun on the question.
For applications that aren't Rails, one just has to create a
Rakefile
and put the task there.Hope this helps other people.
Cheers!