Tuesday, 21 October 2014

The core issue we face before using the
explanation of the use of process managment tools/gems:

While I have implemented sidekiq to
monitor the threads in our application for sending emails in certain
time frames. The sidekiq stops if server reboots and the queued
processes goes in a indefinite period of time without execution. So
this needs the sidekiq should be restarted automatically when it
stops.

Let us start with basic examples, how
to write codes to execute the processes using God.

Let us create a new file god_demo.rb in
application folder.

Write the following code in the same
file

loop do

puts 'Hello'

sleep 1

end

Now we'll write a god config file that
tells god about our process. Place it in the same directory and call
it god_demo .god:

God.watch do |w|

w.name = "god_demo"

w.start = "ruby
/full/path/to/god_demo.rb"

w.keepalive

end

God configuration should start with a
God.watch block. A watch in god represents a process that we want to
watch and control. Each watch must have, at minimum, a unique name
and a command that tells god how to start the process.
The keepalive declaration denotes
god to keep this process alive. If the process is not running when
god starts, it will be started. If the process dies, it will be
restarted.

To run god, we give it the
configuration file we wrote with -c. To
see what's going on, we can ask it to run foreground with -D:

There are two ways that god can monitor
your process. The first and better way is with process events. Not
every system supports it, but those that do will automatically use
it. With events, god will know immediately when a process exits. For
those systems without process event support, god will use a polling
mechanism. The output you see throughout this section will show both
ways.