[Backgroundrb-devel] Multiple args

Eugenol eugenol at gmail.com
Sat Aug 12 11:07:04 EDT 2006


Hi

It seems the following code do not transfer multiple arguments to the
worker instance:

controller:
=======
# recipients = Hash
# mailing = Mailing model instance
session[:job_key] = MiddleMan.new_worker( :class => :mail_queue_worker,
                                              :args => { :recipients
=> recipients, :mailing => mailing },
                                              :ttl => 800 )

mail_queue_worker.rb:
================

require File.dirname(__FILE__) + "/../../config/environment.rb"
ActionMailer::Base.template_root =
File.expand_path(File.dirname(__FILE__) + "/../../app/views")

class MailQueueWorker < BackgrounDRb::Rails

  attr_accessor :progress

  def do_work(args)
    @progress = 0
    @logger.info("MailQueueWorker: start sending newsletter
#{args[:mailing].title}")
    @logger.info( args.to_s )
    for member_email in args[:recipents]
      Newsletter.deliver_send_mailing(args[:mailing], member_email)
      @progress += 100/args[:recipents].size
    end
    @progress = 100
    @logger.info("MailQueueWorker: end sending newsletter
#{args[:mailing].title}")
  end

end



And I get the following error:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.each - (NoMethodError)
/usr/home/act/mailing/config/../script/backgroundrb/../../config/../lib/workers/mail_queue_worker.rb:17:in
`do_work'


Is there any mistake I pasted here ?

Thanks for your help


More information about the Backgroundrb-devel mailing list