module RailsDaemons::Worker::ClassMethods
Public Instance Methods
daemonize()
click to toggle source
# File lib/rails_daemons/worker.rb, line 168 def daemonize self.new.daemonize end
get_pid()
click to toggle source
# File lib/rails_daemons/worker.rb, line 182 def get_pid return unless File.exists?( pid_file ) File.read( pid_file ).to_i end
pid_file()
click to toggle source
# File lib/rails_daemons/worker.rb, line 187 def pid_file Utils.join( 'tmp', 'pids', "#{worker_name}.#{Rails.env}.pid" ) end
running?( pid )
click to toggle source
# File lib/rails_daemons/worker.rb, line 195 def running?( pid ) return false if pid.blank? # https://github.com/ghazel/daemons/blob/d09e132ea67001ba4d6bf6481fb53c4bd4fd9195/lib/daemons/pid.rb#L17 # Check if process is in existence # The simplest way to do this is to send signal '0' # (which is a single system call) that doesn't actually # send a signal begin Process.kill(0, pid) return true rescue Errno::ESRCH return false rescue ::Exception # for example on EPERM (process exists but does not belong to us) return true end end
stop()
click to toggle source
# File lib/rails_daemons/worker.rb, line 172 def stop pid = get_pid if running?( pid ) Process.kill( 'INT', pid ) else puts "Worker #{name} (#{pid}) not running" end end
worker_name()
click to toggle source
# File lib/rails_daemons/worker.rb, line 191 def worker_name name.underscore end