[Backgroundrb-devel] enqueued tasks running but not needed

Matt Garland alias at pet-theory.com
Thu Oct 2 14:17:53 EDT 2008


I have two workers--jabber_worker, election_worker--and both are  
working great.

BUT I can see in my rails console that the queue table is being  
constantly polled for jabber_worker:

   BdrbJobQueue Load (0.002401)   SELECT * FROM `bdrb_job_queues`  
WHERE (`bdrb_job_queues`.`taken` = 0 AND  
`bdrb_job_queues`.`worker_name` = 'jabber_worker') LIMIT 1 FOR UPDATE

  EVEN though my configuration file rules out enqueued tasks:

:backgroundrb:
   :port: 22222
   :ip: 0.0.0.0
   :environment: development
   :log: foreground
   :debug_log: true
   :persistent_disabled: true

I'm not sure why this is happening. It's true that I created  
jabber_worker BEFORE changing the configuration. But even when I rerun  
the rake set up, this persists.

So why is the config overrun? And why only for :jabber_worker?

I should say I am on OS X.

I should also say I don't understand exactly what the persisted queue  
is. I imagine it is useful for long-running jobs when some kind of  
logic is being applied to what goes next, and that logic can change.

That's not my case. jabber_worker just contacts a jabber server,  
pushing data out, adding and deleting users. election_worker maintains  
separate threads for a group of chat rooms, and kills or restarts them  
when the rails app tells it to, and it tells the rails app when an  
election period in a chat room is over and votes need to be counted.

Here's jabber worker:

class JabberWorker < BackgrounDRb::MetaWorker

   require 'xmpp4r/client'
   require 'xmpp4r/muc'

   set_worker_name :jabber_worker

   def create(args = nil)
     jid = Jabber::JID.new("#{JABBER_ADMIN}@#{JABBER_ADDRESS}/rails")
     @client = Jabber::Client.new(jid)
     @client.connect
     @client.auth(JABBER_PWD)
     @client.send(Jabber::Presence.new)
     @conferenceClient={}
     create_chats
   end

   def create_chats
     Chat.all.each do |chat|
       muc = Jabber::MUC::SimpleMUCClient.new(@client)
       @conferenceClient[chat.name]=muc
       address = "#{chat.name}@#{JABBER_CONFERENCES}.#{JABBER_ADDRESS}/ 
rails"
       muc.join(Jabber::JID.new(address))
     end
   end

   def add_jabber_user(user)
     jid = Jabber::JID.new("#{user.login}@#{JABBER_ADDRESS}")
     client = Jabber::Client.new(jid)
     client.connect
     client.register(user.login)
     client.disconnect
   end

   def delete_jabber_user(user)
    jid = Jabber::JID.new("#{user.login}@#{JABBER_ADDRESS}")
    client = Jabber::Client.new(jid)
    client.connect
    client.auth(user.login)
    client.remove_registration
    client.disconnect
   end

   def push_individual_resource(args)
     jid = Jabber::JID.new("#{args[:login]}@#{JABBER_ADDRESS}")
     message = Jabber::Message::new(jid,  
args[:message]).set_type(:normal)
     @client.send(message)
   end

   def push_conference_resource(args)
      jid =  
Jabber 
::JID.new("#{args[:chat_name]}@#{JABBER_CONFERENCES}.#{JABBER_ADDRESS}")
      message = Jabber::Message::new(jid,  
args[:message]).set_type(:groupchat)
      @conferenceClient[args[:chat_name]].send(message)
   end


end

And here is election_worker for comparison:

class ElectionWorker< BackgrounDRb::MetaWorker

   set_worker_name :election_worker

   ELECTION_INTERVAL=10

   def create(args = nil)
      p "election worker created"
     @timers={}
   end

   def stop_elections(chat_id)
     if @timers.key? chat_id
       @timers[chat_id].kill
     end
     p "elections stopped for #{chat_id}"
   end

   def start_elections(chat_id)
     p "elections started for #{chat_id}"
      @timers[chat_id]=fresh_election_timer(chat_id)
       p "elections started for #{chat_id} AFTER"
   end

   def restart_election_cycle(chat_id)
     stop_elections(chat_id)
     start_elections(chat_id)
   end

   def fresh_election_timer(chat_id)
     p "fresh timer #{chat_id}"
     timer=Thread.new do
       loop do
         sleep ELECTION_INTERVAL
         Chat.find(chat_id).do_election
       end
     end
     timer
   end

end


More information about the Backgroundrb-devel mailing list