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.
-
1
Pingback on Feb 11th, 2008 at 8:54 pm
[...] Tips for Debugging BackgroundDRB [...]
-
2
Pingback on Feb 11th, 2008 at 11:59 pm
[...] To debug backgroundrb problems. Its always a good idea to start bdrb in foreground mode by skipping ’start’ argument while start the bdrb server. After that, you should fire rails console and try invoking your tasks from rails console and find out whats happening. John Yerhot has posted an excellent write up about this, here [...]
Leave a Comment
Latest Entries
- Obligatory Google Chrome Post
- rQuote - Ruby on Rails Stock Quote Plugin
- One year older
- Testing Your Apps.
- rDigg - Ruby on Rails Digg API plugin
- Simple Meta Programming in Ruby
- Google Street View Car in Duluth
- Uncrappifying your Qwest Modem (if it is a GT-701WG that is)
- Moved Hosts again..
- m night sucksalot
Feb 11th, 2008 at 12:04 pm
Any ideas on how can we make this process less painful? We can have a bdrb console, for debugging or stepping through worker methods.
Feb 11th, 2008 at 12:48 pm
Hey Hemant -
For me if there was a way to start backgroundrb not like a demon - so there was output like just running script/server - would be helpful to me.
But of course, if there were a console that would be helpful also.
Thanks for being so attentive Hemant.
May 18th, 2008 at 11:50 pm
Hi,
I am using backgroundrb to receive emails in my rails app. But I am unable to start the Backgroundrb server. After doing this:
$ ./script/backgroundrb/start
I am getting following error:
———————————————————————————————
vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:263:in `load_missing_constant’: uninitialized constant BackgrounDRb::MetaWorker (NameError)
from /home/shashank/atul/live_apps/7_qlubb/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:452:in `const_missing’
from ./script/backgroundrb/../../config/../lib/workers/mailreceiver_worker.rb:3
——————————————————————————-
Here is my worker: mailreceiver_worker.rb:3
require ‘rubygems’
require ‘pop_ssl’
class MailreceiverWorker < BackgrounDRb::MetaWorker
set_worker_name :mailreceiver_worker
def create(args = nil)
# this method is called, when worker is loaded for the first time
end
def receive_emails
# I am receiving emails here..
end
—————————————————————————————–
I tried running some examples, and found that worker with do_work are starting but those derived from MetaWorker are not.
I am using latest back-drb release.
Can you pl help me out of this?
Thanks in advance.
Atul
May 19th, 2008 at 8:20 am
@Atul
Did you check out the Git version of backgrounDRb? I’ve heard some people having issues similar to yours with the Git version and they magically fix themselves after using the SVN version.
Also, what is in you /config/backgroundrb.yml file?
May 22nd, 2008 at 12:52 am
@John.
Thanks for reply. I dont have Git version of backgrounDRrb. I have done :
“$ ruby script/plugin install http://svn.devjavu.com/backgroundrb/trunk backgoundrb ”
One more error I have found is that when I run ‘./script/backgroundrb/start’ after previous command I get following error:
—————————————————————-
./script/backgroundrb/start:4:in `require’: no such file to load — script/backgroundrb/../../config/../vendor/plugins/backgroundrb/backgroundrb.rb (LoadError)
from ./script/backgroundrb/start:4
——————————————————-
This might be coz “rake backgroundrb:setup” doesnt install backgroundrb.rb and backgroundrb_rails.rb files, is coz of different versions of back-DRb.
Here is a snapshot of my backgroundrb.yml :
—
:backgroundrb:
:ip: localhost
:port: 11006
:environment: development
:log: foreground
—
Here is a snapshot of a irb seesion
——————————————————-
Loading development environment.
>> MiddleMan.worker(:billing_worker).charge_customer()
{:type=>:do_work, :worker=>:billing_worker, :worker_method=>:charge_customer}
BackgrounDRb::BdrbConnError: BackgrounDRb::BdrbConnError
from /home/atul/apps/7/vendor/plugins/backgroundrb/lib/backgroundrb.rb:81:in `dump_object’
from /home/atul/apps/7/vendor/plugins/backgroundrb/lib/backgroundrb.rb:93:in `ask_work’
from /home/atul/apps/7/vendor/plugins/backgroundrb/lib/backgroundrb/rails_worker_proxy.rb:26:in `method_missing’
from (irb):1
——————————————————-
Hope you will find some clues in this. I really appreciate any help I can get on this.
Thanks,
Atul
May 27th, 2008 at 6:32 am
@Atul
I wish I had some useful insights for you on the problem. Honestly, I’d try to just re-install the plugin.
I had horrible problems when I first installed the plugin and for some magic reason, they were solved by a re-install.