I needed a way to send emails to users if certain data in the system had not been updated for 4 hours.

I thought that RailsCron would be the best solution developed by Kyle Maxwell. Unfortunatly his site and wiki was down. So I could not see how to use it correctly, as the readme was a bit vauge. So I thought I would post some simple code here to help some people on how to use RailsCron.

First of all I wanted to use ActsAsBackground on a Model Class. Here is the code :

class Comment < ActiveRecord::Base
  # This is the key thing.  I am not sure why it does not use acts_as_background
  include ActsAsBackground
  # This defines what method you want to use
  background :deliver, :every => 1.minute

def self.deliver
   #code here

What I was confused on was how to use acts as background. I managed to find a cached version of Kyle’s page and see it in action. I am sure there is a reason that it is not acts_as_background and why you need the include directive.

The next thing took me a while to figure out as well :). To actually use RaisCron you need to start it with a rake command like so :

rake cron_start

The rest of the comands are in the readme file. I hope this helps someone out there.



1 comment so far

  1. ratul on

    your post is not clear enough to build a railscron
    job. Will you please describe this in detail.
    where do i find the readme file?????


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: