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
# File 'lib/worker_killer/killer.rb', line 7

def initialize(logger: nil, **_kwargs)
  @logger = logger
  @config = WorkerKiller.configuration
  @kill_attempts = 0
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:



26
27
28
# File 'lib/worker_killer/killer.rb', line 26

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

#kill(start_time, **params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/worker_killer/killer.rb', line 13

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

  @kill_attempts += 1

  sig = :QUIT
  sig = :TERM if kill_attempts > config.quit_attempts
  sig = :KILL if kill_attempts > (config.quit_attempts + config.term_attempts)

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

#loggerObject

:nocov:



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

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