Class: RabbitJobs::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbit_jobs/util.rb

Class Method Summary collapse

Class Method Details

.check_pidfile(pidfile) ⇒ Object

clean old worker process



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rabbit_jobs/util.rb', line 8

def check_pidfile(pidfile)
  if File.exists?(pidfile)
    pid = File.read(pidfile).to_i
    begin
      Process.kill(0, pid)
      RJ.logger.info "Killing stale rj_worker[##{pid}]"
      Process.kill("TERM", pid)

      while Process.kill(0, pid)
        sleep(0.5)
      end
    rescue
      File.delete(pidfile) if File.exists?(pidfile)
    end
  end
end

.cleanup_backtrace(trace_lines) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/rabbit_jobs/util.rb', line 25

def cleanup_backtrace(trace_lines)
  if defined?(Rails) && Rails.respond_to?(:root)
    rails_root_path = Rails.root.to_s
    trace_lines.dup.keep_if { |l| l[rails_root_path] }
  else
    trace_lines
  end
end