ruby 1.8.7 multithread mail 'uninitialized constant (NameError)' -


my script sends emails list of users. need multithreading because error in 1 address crashes app. implementation:

  require 'thread'   <...>   lock = mutex.new   lock.synchronize {     @model.certs.each{ |user|       @threads << thread.new(user) { |data|       = "#{data['name']} #{data['surname']} <#{data['email']}>"       subject = '<subject>'       body = "<body>"       view = view.new()       view.to =       view.body = body       view.subject = subject       view.attachment = ''       view.sendmessage()       @model.sended(data['email'])       }     }   }    @threads.each { |t|     begin       t.join     rescue => err       $log.fatal(err)     end   } 

view.sendmessage consists:

require 'mail' require 'net/smtp' <...> smtp = net::smtp.start(@mailserver) mail = mail.new() mail.from = @from mail.to = @to mail.subject = @subject mail.body = @body if !@attachment.empty?   mail.add_file @attachment end mail.delivery_method :smtp_connection, {   :connection => smtp } mail.deliver 

and sometimes gives such mistakes as:

uninitialized constant mail::field::fromfield (nameerror) /var/lib/gems/1.8/gems/mail-2.4.4/lib/mail/field.rb:189:in `new_field' 

or

uninitialized constant mail::commonaddress::addresslist (nameerror) /var/lib/gems/1.8/gems/mail-2.4.4/lib/mail/fields/common/common_address.rb:9:in `parse' 

i have no idea, how can fixed. mutex adding has no result.

@frederickcheung right require in threads. aditionally, need threads? wrong with:

emails.each |mail|   begin     mail.deliver   rescue thecorrectexceptionforinvalidemails     puts "invalid e-mail: x"     method_to_remove_invalid_email_from_database   end end 

even if let empty block rescue, in invalid e-mail, jump , continue executing.


Comments