Backgroundrb

How I made BackgrounDRb work

First of all follow the instructions in the home page of the project: http://backgroundrb.rubyforge.org/

Second, I'm on a Mac OS X so maybe, if you're on a different OS, the address binding problem won't exist for you.

Configuring backgrounDRb

I would like a worker named :feeder_worker to be scheduled for execution of its feed() method every 15 mins. So I did this backgroundrb.yml

---
:backgroundrb:
  :port: 11006 # port to start listen
  :ip: localhost # host to listen
  :log: foreground # foreground mode,print log messages on console
:schedules:
  :feeder_worker:
    :feed:
      :trigger_args:
          :start: <%= Time.now + 5.seconds %>
          :repeat_interval: <%= 15.minutes %>
...

The first thing that fails is the host ip configuration which is 'localhost' by default. The error I get is:

Starting BackgrounDRb .... /Library/Ruby/Gems/1.8/gems/packet-0.1.15/lib/packet/packet_core.rb:126:in `bind': Address family not supported by protocol family - bind(2) (Errno::EAFNOSUPPORT)
    from /Library/Ruby/Gems/1.8/gems/packet-0.1.15/lib/packet/packet_core.rb:126:in `start_server'
    from /Users/oriberu/prog/ruby/factory/negociscat/vendor/plugins/backgroundrb/server/lib/master_proxy.rb:17:in `initialize'
    from /Library/Ruby/Gems/1.8/gems/packet-0.1.15/lib/packet/packet_master.rb:19:in `run'
    from /Users/oriberu/prog/ruby/factory/negociscat/vendor/plugins/backgroundrb/server/lib/master_proxy.rb:14:in `initialize'
    from /Users/oriberu/prog/ruby/factory/negociscat/vendor/plugins/backgroundrb/lib/backgroundrb/bdrb_start_stop.rb:109:in `new'
    from /Users/oriberu/prog/ruby/factory/negociscat/vendor/plugins/backgroundrb/lib/backgroundrb/bdrb_start_stop.rb:109:in `start_bdrb'
    from /Users/oriberu/prog/ruby/factory/negociscat/vendor/plugins/backgroundrb/lib/backgroundrb/bdrb_start_stop.rb:16:in `start'
    from script/backgroundrb:24

To solve this, simply change 'localhost' for '127.0.0.1'.

The next thing that is not working for me is the starting of the worker. The BackgrounDRb server is not executing the FeederWorker.feed() operation neither 5secs after bootstrapping the server neither every 15mins. The cause seems to be this error:

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/date/format.rb:959:in `dup': can't dup Nil
Class (TypeError)
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/date/format.rb:959:in `_parse
'
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/time.rb:240:in `parse'
        from /Users/oriberu/prog/ruby/factory/negociscat/vendor/plugins/backgroundrb/server/lib/trigger.rb:8:in `i
nitialize'
        from /Users/oriberu/prog/ruby/factory/negociscat/vendor/plugins/backgroundrb/server/lib/meta_worker.rb:286
:in `new'
        from /Users/oriberu/prog/ruby/factory/negociscat/vendor/plugins/backgroundrb/server/lib/meta_worker.rb:286
:in `new_load_schedule'
        from /Users/oriberu/prog/ruby/factory/negociscat/vendor/plugins/backgroundrb/server/lib/meta_worker.rb:279
:in `each'
        from /Users/oriberu/prog/ruby/factory/negociscat/vendor/plugins/backgroundrb/server/lib/meta_worker.rb:279
:in `new_load_schedule'
        from /Users/oriberu/prog/ruby/factory/negociscat/vendor/plugins/backgroundrb/server/lib/meta_worker.rb:124
:in `worker_init'
        from /Library/Ruby/Gems/1.8/gems/packet-0.1.15/bin/../lib/packet/packet_worker.rb:19:in `start_worker'
        from /Library/Ruby/Gems/1.8/gems/packet-0.1.15/bin/packet_worker_runner:33:in `load_worker'
        from /Library/Ruby/Gems/1.8/gems/packet-0.1.15/bin/packet_worker_runner:26:in `initialize'
        from /Library/Ruby/Gems/1.8/gems/packet-0.1.15/bin/packet_worker_runner:47:in `new'
        from /Library/Ruby/Gems/1.8/gems/packet-0.1.15/bin/packet_worker_runner:47
        from /usr/bin/packet_worker_runner:19:in `load'
        from /usr/bin/packet_worker_runner:19

Caused because the absence of the :end: time limit. Thus this is a mandatory parameter. But sometimes workers have an unknown running time.
But I took this limitation/feature as a good practice, now I'm setting a limit of 2mins which is more than the necessary time for reading an RSS and persist to db the links in it. This ensures me that any worker which is not running properly will be stopped and rerun later. The resultant backgroundrb.yml:

---
:backgroundrb:
  :port: 11006 # port to start listen
  :ip: 127.0.0.1 # host to listen
:schedules:
  :feeder_worker:
    :feed:
      :trigger_args:
        :start: <%= Time.now + 5.seconds %>
        :end: <%= Time.now + 2.minutes %>
        :repeat_interval: <%= 10.minutes %>
...

As a workaround you can use the Cron style notation giving a bakgroundrb.yml like:

---
:backgroundrb:
  :port: 11006 # port to start listen
  :ip: 127.0.0.1 # host to listen
:schedules:
  :feeder_worker:
    :feed:
      :trigger_args: 0 */15 * * * *
...

but
Hope this helps!

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License