Class: Resque::Plugins::WorkerKiller::PrivateMethods
- Inherits:
-
Object
- Object
- Resque::Plugins::WorkerKiller::PrivateMethods
- Defined in:
- lib/resque/plugins/worker_killer.rb
Instance Method Summary collapse
-
#initialize(obj) ⇒ PrivateMethods
constructor
A new instance of PrivateMethods.
-
#kill_self(logger, start_time) ⇒ Object
Kill the current process by telling it to send signals to itself If the process isn’t killed after ‘@max_term` TERM signals, send a KILL signal.
- #monitor_oom ⇒ Object
- #one_shot_monitor_oom(start_time) ⇒ Object
- #plugin_name ⇒ Object
Constructor Details
#initialize(obj) ⇒ PrivateMethods
Returns a new instance of PrivateMethods.
37 38 39 |
# File 'lib/resque/plugins/worker_killer.rb', line 37 def initialize(obj) @obj = obj end |
Instance Method Details
#kill_self(logger, start_time) ⇒ Object
Kill the current process by telling it to send signals to itself If the process isn’t killed after ‘@max_term` TERM signals, send a KILL signal.
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/resque/plugins/worker_killer.rb', line 78 def kill_self(logger, start_time) alive_sec = (Time.now - start_time).round @@kill_attempts ||= 0 @@kill_attempts += 1 sig = :TERM sig = :KILL if @@kill_attempts > max_term logger.warn "#{plugin_name}: send SIG#{sig} (pid: #{Process.pid}) alive: #{alive_sec} sec (trial #{@@kill_attempts})" Process.kill(sig, Process.pid) end |
#monitor_oom ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/resque/plugins/worker_killer.rb', line 58 def monitor_oom start_time = Time.now loop do one_shot_monitor_oom(start_time) sleep monitor_interval end end |
#one_shot_monitor_oom(start_time) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/resque/plugins/worker_killer.rb', line 66 def one_shot_monitor_oom(start_time) rss = GetProcessMem.new.kb logger.info "#{plugin_name}: worker (pid: #{Process.pid}) using #{rss} KB." if verbose if rss > mem_limit logger.warn "#{plugin_name}: worker (pid: #{Process.pid}) exceeds memory limit (#{rss} KB > #{mem_limit} KB)" kill_self(logger, start_time) end end |
#plugin_name ⇒ Object
54 55 56 |
# File 'lib/resque/plugins/worker_killer.rb', line 54 def plugin_name "Resque::Plugins::WorkerKiller" end |