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 incoming Queue.
What I want to do is when I start my rails server the Poller should be start 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 way 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 stop it. Open4.popen4 will do the trick. You would have to do Process.detach(pid) after popen, else you will have harmless defunct zombie processes hanging around.