Class: WorkerKiller::Killer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/worker_killer/killer.rb

Direct Known Subclasses

DelayedJob, Passenger, Puma, Signal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil, **_kwargs) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
# File 'lib/worker_killer/killer.rb', line 7

def initialize(logger: nil, **_kwargs)
  @logger = logger
  @config = WorkerKiller.configuration
  @kill_attempts = 0
  @sig = nil
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#kill_attemptsObject

Returns the value of attribute kill_attempts.



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

def kill_attempts
  @kill_attempts
end

Instance Method Details

#do_kill(*_args) ⇒ Object

:nocov:



32
33
34
# File 'lib/worker_killer/killer.rb', line 32

def do_kill(*_args)
  raise 'Not Implemented'
end

#kill(start_time, **params) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/worker_killer/killer.rb', line 14

def kill(start_time, **params)
  alive_sec = (Time.now - start_time).round

  @kill_attempts += 1

  case @sig
  when nil
    @sig = :QUIT
  when :QUIT
    @sig = :TERM
  when :TERM
    @sig = :KILL
  end

  do_kill(@sig, Process.pid, alive_sec, **params)
end

#loggerObject

:nocov:



37
38
39
# File 'lib/worker_killer/killer.rb', line 37

def logger
  @logger ||= WorkerKiller.configuration.logger
end