views:

66

answers:

3

Hi there!

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

A: 

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!

Eric Koslow
A: 

Hi Eric,

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 :)

$ 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

have fun, Francisco

include
Looks, good. Unfortunately Heroku doesn't support the Rufus gem yet.
Eric Koslow
autch! Maybe http://github.com/javan/whenever of maybe they dont support any of then regarding their payed "cron" add-on :/
include
+1  A: 

You need a Rakefile like:

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

Heroku periodically executes rake cron in your app depending on whether you have selected the "cron add-on" to be hourly or daily.

Himanshu