Class: CronoTrigger::Models::Signal

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/crono_trigger/models/signal.rb

Constant Summary collapse

IGNORE_THRESHOLD =
300

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.send_cont(worker_id) ⇒ Object



36
37
38
# File 'lib/crono_trigger/models/signal.rb', line 36

def send_cont(worker_id)
  send_signal("CONT", worker_id)
end

.send_signal(signal, worker_id) ⇒ Object



24
25
26
# File 'lib/crono_trigger/models/signal.rb', line 24

def send_signal(signal, worker_id)
  create!(signal: signal, worker_id: worker_id, sent_at: Time.current)
end

.send_term(worker_id) ⇒ Object



28
29
30
# File 'lib/crono_trigger/models/signal.rb', line 28

def send_term(worker_id)
  send_signal("TERM", worker_id)
end

.send_tstp(worker_id) ⇒ Object



40
41
42
# File 'lib/crono_trigger/models/signal.rb', line 40

def send_tstp(worker_id)
  send_signal("TSTP", worker_id)
end

.send_usr1(worker_id) ⇒ Object



32
33
34
# File 'lib/crono_trigger/models/signal.rb', line 32

def send_usr1(worker_id)
  send_signal("USR1", worker_id)
end

Instance Method Details

#kill_me(to_supervisor: true) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/crono_trigger/models/signal.rb', line 45

def kill_me(to_supervisor: true)
  if update(received_at: Time.current)
    if to_supervisor && Process.ppid != 1
      Process.kill(signal, Process.ppid)
    else
      Process.kill(signal, Process.pid)
    end
  end
end