How to start cron in Heroku using the Sinatra app

I am writing a tiny Sinatra application and I want to host it on Heroku for simplicity. But I have a task that cuts off some sites and adds some data to my database every hour. Currently, it is simply written as a ruby ​​script that must be executed. What Heroku has a rake based cron job . Now, if it was a rails application, I could easily do it, but I want to avoid clutter for something as simple as this.

Is there any way to avoid this? Or do I need to rake also with my application?

Thank.

Eric

+5
source share
3 answers

You need a Rakefile, for example:

desc "This task is called by the Heroku cron add-on"
task :cron do
 # Do something
end

Heroku periodically launches rake cron in your application, depending on whether you selected cron add-on both hourly and daily.

+10
source

You need to check out Rufus. Rufus is your friend. Rufus will be your crontab while your application is downloaded.

I have not tried this material on Heroku, but try and answer us.

http://codex.heroku.com/past/2010/4/15/rufus_scheduler_for_my_tiny_sinatra_apps/

Why is Rufus cool? Well check it out, it's clean :)

$ sudo gem install rufus-scheduler

require 'rubygems'
require 'rufus/scheduler'

scheduler = Rufus::Scheduler.start_new

scheduler.cron '00 23 30 * *' do
  # Run every 30 days at 23h00m
  # ...your magic code goes here...
end
+3
source

, , .

, Rails, Rakefile .

, .

!

+1

All Articles