lundi 22 mai 2017

How to initialise a method in a ruby class on rails server start up

I have created ruby thread which keep polling messages from Queue. The following is the basic code block which keeps polling the queue infinitely.How could i initialise this method (poll method in class Poller ) on rails server start up so that this code(infinite loop thread) block runs when the application starts

class Poller
 class << self
  def poll
    begin 
      ----polling logic for queue
      sleep(1.minute)
    end while(true)
  end

 end
end

How do i initialise above code in a rails initialisers so that the above code will start polling messages from queue?

Aucun commentaire:

Enregistrer un commentaire