Saturday, 21 March 2009

backgroundrb by hostname

I love backgroundrb - the way to run scheduled tasks and async workers. BUT on my setup I wanted to run certain backgroundrb tasks on one machine and certain ones on another (for memory reasons and also for testing).

I couldn't find something that did that so I forked backgroundrb into my own repository on GitHub. You can find it here.

You can now have a config file like this:
# A Sample YAML configuration file
:ip: #ip on which backgroundrb server is running
:port: 11006 #port on which backgroundrb server is running
:environment: production # rails environment loaded, defaults to development
:debug_log: true # whether to print debug logs to a seperate worker, defaults to true
:log: foreground # will print log messages to STDOUT, defaults to seperate log worker
# :result_storage: memcache # store results in a mecache cluster, you also need to specify location of your memcache clusters in next section
:persistent_disabled: true # turn this off if your application doesn't use backgroundrb's persistent/enqueued tasks system
:persistent_delay: 10 # the time (seconds) between each time backgroundrb checks the database for enqueued tasks
:per_environment: true

# You specify your worker schedules here
:environment: test
:test_worker: # worker name
:test: #worker method
:trigger_args: */5 * * * * * * #worker schedule
:data: whatever

:environment: development
:test_worker: # worker name
:test: #worker method
:trigger_args: */5 * * * * * * #worker schedule
:data: phil

You can launch backgroundrb with a specific hostname like this:

./script/backgroundrb --hostname=whatever.local

I've created Capistrano tasks that fire up an instance on 2 servers and now they act differently based on hostname.


Friday, 13 March 2009

Generating sitemaps and xml catalogues

One of the things we have to do at FilmAmora is generate a catalogue of our films. This is used in a few ways, but principally to drive our recommendations system.

I stumbled across this great blog entry:
Generating-Sitemaps-With-Rails that not only tells you a very nice way of generating sitemaps but also gave us great ideas for using the same technique to generate our catalogues.