Archive for the ‘backgroundrb’ Category

Debugging Backgroundrb

Monday, February 11th, 2008

Backgroundrb is a great tool for getting cron like functionality in your Rails app, but it can be a pain if its not working correctly. I’m not going to go into how to get backgroundrb working, its rubyforge page has decent instructions for that, but what I will share are some tips on debugging a non-working worker.

Obviously check your RAILS_ROOT/log and check backgroundrb.log, backgroundrb_server.log, and backgroundrb_debug.log. I’ve found backgroundrb.log most useful, but many times I’ll restart backgroundrb by

script/backgroundrb stop

script/backgroundrb start #restart doesn’t work for me

and nothing will happen. Check your backgroundrb_server.log file and you may see that the ‘address is already in use”.

Type “top” into your command line (on a Linux system) and then press shift+M. You should get a nice list of services running and you’ll more than likely have a couple of rubys on there. For some reason backgroundrb doesn’t stop all the time when you tell it to and I’ve had to kill -9 the rubys and then restart backgroundrb and mongrel.

You may also notice that the backgroundrb ruby instance uses ALOT of memory! Make sure you have

:environment: production

in your backgroundrb.yml file in RAILS_ROOT/config. Otherwise backgroundrb is working in development mode.

Finally, to debug an syntax or other error try this.

1. open 2 command lines.

2. start your rails app with ruby script/server. Make sure to start it in development mode and not using mongrel_rails.

3. start backgroundrb in the other terminal.

4. watch the first terminal and you can see what background rb is doing and where exactly it gets messed up.

You can do this by monitoring the log file or tailing it, but I like this better and it provides you with more info.

Hope this helps any of you out.