Job scheduler in RoR

by Noman Muhammad

BackgroundRb is a Ruby job server and scheduler. In this post i'll create a simple RoR project in which using backgrounDRb we will fetch data from database and logged them in the log file.

1) pre-requisites: two gem => chronic, packet [in my case the current version of packet doesn't work, so i download the packet version: 0.1.5 from rubyforge and then manually install it]
(*) install chronic :
~# sudo gem install chronic
(*) install packet :
~# sudo gem install /path/to/your/directory/packet-0.1.5.gem

2) download backgrounDRb from http://github.com/gnufied/backgroundrb/tree/master and extract the .tar/.zip file and rename the folder backgroundrb. Store this folder in projects_name/vendor/plugins

3) now setup backgrounDRb
~# rake backgroundrb:setup

4) now create your own worker class
~# ./script/generate worker fetcher
---- here fetcher is the worker name, this command will create fetcher_worker.rb file in /libs/worker folder. my fetcher_worker.rb is as follows:
----------------------------------------------------------------------------------------------

class FetcherWorker < BackgrounDRb::MetaWorker
set_worker_name :fetcher_worker

def create(args = nil)
#this method is called, when worker is loaded for the first time
logger.info "Created feeds worker"
end

def update()
logger.info "Hello UPDATE"
@posts = Post.find(:all)

for post in @posts
logger.info post.name
end
end
end

---------------------------------------------------------------------------------------

This entry was posted on Sunday, February 22, 2009 and is filed under , , . You can leave a response and follow any responses to this entry through the Subscribe to: Post Comments (Atom) .

0 comments