[Backgroundrb-devel] Multiple args

Ezra Zygmuntowicz ezmobius at gmail.com
Sat Aug 12 18:48:10 EDT 2006


Hi Eugene-

	I think there must be an error somewhere. Can you show me what the  
output is if you do @logger args.inspect  right at the beginning of  
your do_work method. then look in the log file and show us what is  
output. Also if  :recipients is a hash then you need to treat it like  
one.

So this:

     for member_email in args[:recipents]
       Newsletter.deliver_send_mailing(args[:mailing], member_email)
       @progress += 100/args[:recipents].size
     end

Should be something like this

     args[:recipents].each do |key, val|
       Newsletter.deliver_send_mailing(args[:mailing], <*>) # replace  
the <*> with either the key or val
                                                                         
                                # depending on how your hash is  
structured.
       @progress += 100/args[:recipents].size # and this won't do  
what you think it might do. It will
                                                                         
        # always be the same size as the original entire hash
                                                                         
        #because you don't delete any members.
     end



	I would suggest you test out your code in script/console or  
something so you know that it works and then put it in a worker. It  
seems like your args just aren't what you are expecting them to be.  
If you can paste back the section of the log where you called @logger  
args.inspect   I can help you code up how to use the args correctly.


Cheers-
-Ezra



On Aug 12, 2006, at 8:07 AM, Eugenol wrote:

> 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
> _______________________________________________
> Backgroundrb-devel mailing list
> Backgroundrb-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/backgroundrb-devel



More information about the Backgroundrb-devel mailing list