Module: DelayedJobRestart

Defined in:
lib/delayed_job_restart.rb

Class Method Summary collapse

Class Method Details

.delayed_job_stop_alertObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/delayed_job_restart.rb', line 9

def delayed_job_stop_alert
  file_path = "#{Rails.root}/tmp/pids/delayed_job.pid"
  if file_exist_status?(file_path)
    dj_id = get_file_content(file_path).to_i
    unless process_running_status?(dj_id)
      send_delayed_job_stop_alert
      start_delayed_job
    end
  else
      send_delayed_job_stop_alert
      start_delayed_job
  end
end

.file_exist_status?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/delayed_job_restart.rb', line 23

def file_exist_status?(file_path)
  File.exist?(file_path)
end

.get_file_content(file_path) ⇒ Object



27
28
29
# File 'lib/delayed_job_restart.rb', line 27

def get_file_content(file_path)
  File.read(file_path).strip
end

.hiObject



5
6
7
# File 'lib/delayed_job_restart.rb', line 5

def self.hi
  puts "Hello world!"
end

.process_running_status?(id) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'lib/delayed_job_restart.rb', line 31

def process_running_status?(id)
  begin
    Process.getpgid(id.to_i)
    true
  rescue
    false
  end
end

.send_delayed_job_stop_alertObject



40
41
42
43
44
# File 'lib/delayed_job_restart.rb', line 40

def send_delayed_job_stop_alert
  Settings.delayed_job_alert_recipients.each do |recipient|
    ActionMailer::Base.mail(to: recipient.to_s, subject: "Delayed Job restart alert", body: "Delayed Job was stopped and it was restarted. Please check.",from: recipient.to_s, reply_to: recipient.to_s).deliver!
  end
end

.start_delayed_jobObject



46
47
48
# File 'lib/delayed_job_restart.rb', line 46

def start_delayed_job
  `ruby script/delayed_job start RAILS_ENV=#{Rails.env}`
end