[Backgroundrb-devel] How you want BackgrounDrb to behave

hemant gethemant at gmail.com
Wed Oct 31 19:07:34 EDT 2007


Hi,

Ok, As i promised.. I am working on new version of BackgrounDRB, which
is getting close and will be out soon. I need some feedback from you
guys. So, please reply back.

The code has changed significantly and its no longer using DRB. But I
will keep the name BackgroundRb. Ok, in new API, a worker looks like
this:

require "net/smtp"
require "guid"

class NewsletterWorker < Packet::Worker
  set_worker_name :newsletter_worker
  def worker_init
    puts "starting the worker"
  end

  def receive_data p_data
  end

  # this is where a request from rails will be received. so implement
this method
  # if you want to trigger your workers from rails.
  def receive_internal_data p_data
    self.send(p_data[:method],p_data[:data])
  end

  def send_mail data
  end
end

And you can invoke a method in worker from rails using:
# invoke method send_mail in newsletter_worker
WorkerProxy.send_request(:worker => :newsletter_worker, :method =>
:send_mail, :data => @newsletter.id)
# No Kidding, guys above code works.

Also, as usual you define your workers in a worker directory and they
will be picked and run.

Now, It should be noted that, part of stability that comes to new
version is because of total lack of threads. Even timers are
implemented using evented model of programming. Right now, we have two
methods "add_timer" and "add_periodic_timer" available in all the
workers, which can be used to schedule a job.

A sample use case is:

def worker_init
   add_periodic_timer(10) { puts "Hello World : #{Time.now}"}
 end

Older version of BackgrounDrb was having a seperate file which was
used for reading worker schedules. I am thinking of getting rid of
that file and making all the workers self contained.
What you guys think?


Things that are not working:
1. There is no worker.delete or self.delete to stop a worker. But
since, your workers are seperate processes, you can call exit on them.
2. Since older version of BackgrounDrb used threads. The famous
progress bar example, that came with initial version of BackgrounDrb
worked. But new version has a event loop around all the workers and
thats how it runs timers and can trigger callbacks. So progress bar
example, will have to reworked using callback mechanism, rather than
threads.


PS: trunk doesn't yet reflect the changes i said. I will be checking
in code soon. stay tuned.


-- 

Let them talk of their oriental summer climes of everlasting
conservatories; give me the privilege of making my own summer with my
own coals.

http://gnufied.org


More information about the Backgroundrb-devel mailing list