I tried wrapping the EM code in a synchronize block and I'm now
getting a deadlock:
=> true
>> Person.find(1234).save
=> true
>> Person.find(1234).save
deadlock 0x21e0710: sleep:F(4) - /usr/local/lib/ruby/1.8/drb/drb.rb:
944
deadlock 0x346fc: sleep:S (main) - /usr/local/lib/ruby/gems/1.8/gems/
wirble-0.1.2/./wirble.rb:418
/usr/local/lib/ruby/1.8/irb.rb:159:in `write': Bad file descriptor
(Errno::EBADF)
from /usr/local/lib/ruby/1.8/irb.rb:159:in `print'
from /usr/local/lib/ruby/1.8/irb.rb:159:in `eval_input'
from /usr/local/lib/ruby/1.8/irb.rb:263:in `signal_status'
from /usr/local/lib/ruby/1.8/irb.rb:147:in `eval_input'
from /usr/local/lib/ruby/1.8/irb/ruby-lex.rb:244:in
`each_top_level_statement'
from /usr/local/lib/ruby/1.8/irb/ruby-lex.rb:230:in `loop'
from /usr/local/lib/ruby/1.8/irb/ruby-lex.rb:230:in
`each_top_level_statement'
from /usr/local/lib/ruby/1.8/irb/ruby-lex.rb:229:in `catch'
from /usr/local/lib/ruby/1.8/irb/ruby-lex.rb:229:in
`each_top_level_statement'
from /usr/local/lib/ruby/1.8/irb.rb:146:in `eval_input'
from /usr/local/lib/ruby/1.8/irb.rb:70:in `start'
from /usr/local/lib/ruby/1.8/irb.rb:69:in `catch'
from /usr/local/lib/ruby/1.8/irb.rb:69:in `start'
from /usr/local/bin/irb:13
My code now looks like:
def before_update
require 'thread'
semaphore = Mutex.new
message = parature_hash.merge({:message_type =>
'update', :lookup_email => parature_email}).to_yaml
AMQP.logging = false
semaphore.synchronize{
AMQP.start(:host => "message_host") do
publish = MQ.queue("/parature", :durable => true).publish
(message.to_s, :persistent => true)
AMQP.stop{EM.stop}
end
}
end