How to automatically call function after server start

Hi, I am implementing Amazon’s SQS service in My Rails application.
I am trying to make a Poller which will continuously monitor the
What I want to do is when I start my rails server the Poller should be
and start monitoring the incoming queue.

Which is the best way to implement this code in my rails app?

Your suggestion will appropriate me.

You could put the start-up code for your Poller in an initializer.

I am thinking to implement using Thread class, but is there any other
which is reliable or stable to implement this task?

You can use an event to start and stop your poller. use the open4 gem to
start a subprocess that gives the pid then use “kill ‘TERM’, pid” to
it. Open4.popen4 will do the trick. You would have to do
after popen, else you will have harmless defunct zombie processes

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs