Class: Wurk::Process
- Inherits:
-
Object
- Object
- Wurk::Process
- Defined in:
- lib/wurk/process_set.rb
Overview
One row in the process list. ‘attribs` is the merged `info` JSON + per-beat fields (busy, beat, quiet, rss, rtt_us). All fields are read-only — mutations happen via signals (`<id>-signals` LIST), not by editing this hash.
Spec: docs/target/sidekiq-free.md §19.6.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #capsules ⇒ Object
-
#dump_threads ⇒ Object
SIGTTIN — dump every thread’s backtrace.
- #embedded? ⇒ Boolean
- #identity ⇒ Object (also: #id)
-
#initialize(hash) ⇒ Process
constructor
A new instance of Process.
- #labels ⇒ Object
-
#leader? ⇒ Boolean
Compares identity against the ‘dear-leader` STRING.
-
#queues ⇒ Object
Back-compat for dashboards predating capsules (pre-v8.0.8).
-
#quiet! ⇒ Object
SIGTSTP — drop fetch, drain in-flight.
-
#stop! ⇒ Object
SIGTERM — graceful shutdown within ‘shutdown_timeout`.
-
#stopping? ⇒ Boolean
Truthy when this process has accepted a TSTP and won’t fetch new jobs.
- #tag ⇒ Object
- #version ⇒ Object
-
#weights ⇒ Object
Back-compat sibling of ‘queues`.
Constructor Details
#initialize(hash) ⇒ Process
Returns a new instance of Process.
159 160 161 |
# File 'lib/wurk/process_set.rb', line 159 def initialize(hash) @attribs = hash end |
Instance Method Details
#[](key) ⇒ Object
165 |
# File 'lib/wurk/process_set.rb', line 165 def [](key) = @attribs[key] |
#capsules ⇒ Object
191 |
# File 'lib/wurk/process_set.rb', line 191 def capsules = self['capsules'] |
#dump_threads ⇒ Object
SIGTTIN — dump every thread’s backtrace. For diagnosing frozen processes that are still beating.
212 213 214 |
# File 'lib/wurk/process_set.rb', line 212 def dump_threads signal('TTIN') end |
#embedded? ⇒ Boolean
193 |
# File 'lib/wurk/process_set.rb', line 193 def = self['embedded'] |
#identity ⇒ Object Also known as: id
166 |
# File 'lib/wurk/process_set.rb', line 166 def identity = self['identity'] |
#labels ⇒ Object
164 |
# File 'lib/wurk/process_set.rb', line 164 def labels = self['labels'].to_a |
#leader? ⇒ Boolean
Compares identity against the ‘dear-leader` STRING. Ent-only; always false in OSS/free.
225 226 227 |
# File 'lib/wurk/process_set.rb', line 225 def leader? Wurk.redis { |c| c.call('GET', 'dear-leader') == identity } end |
#queues ⇒ Object
Back-compat for dashboards predating capsules (pre-v8.0.8). New heartbeats write ‘capsules`; fall through to the legacy `queues` field if the process hasn’t been upgraded yet.
172 173 174 175 176 177 178 |
# File 'lib/wurk/process_set.rb', line 172 def queues if self['capsules'] capsules.values.flat_map { |c| c['weights'].keys }.uniq else self['queues'] end end |
#quiet! ⇒ Object
SIGTSTP — drop fetch, drain in-flight. Asynchronous; takes one heartbeat (≤10s) for the target process to notice.
197 198 199 200 201 |
# File 'lib/wurk/process_set.rb', line 197 def quiet! raise 'Cannot quiet an embedded process' if signal('TSTP') end |
#stop! ⇒ Object
SIGTERM — graceful shutdown within ‘shutdown_timeout`. Asynchronous.
204 205 206 207 208 |
# File 'lib/wurk/process_set.rb', line 204 def stop! raise 'Cannot stop an embedded process' if signal('TERM') end |
#stopping? ⇒ Boolean
Truthy when this process has accepted a TSTP and won’t fetch new jobs. The heartbeat writes ‘quiet = “true”` after handling the signal — read-only here.
219 220 221 |
# File 'lib/wurk/process_set.rb', line 219 def stopping? self['quiet'] == 'true' end |
#tag ⇒ Object
163 |
# File 'lib/wurk/process_set.rb', line 163 def tag = self['tag'] |
#version ⇒ Object
192 |
# File 'lib/wurk/process_set.rb', line 192 def version = self['version'] |
#weights ⇒ Object
Back-compat sibling of ‘queues`. Two capsules processing the same queue name will collapse to a single weight — there’s no useful way to merge them and the dashboard never displayed both.
183 184 185 186 187 188 189 |
# File 'lib/wurk/process_set.rb', line 183 def weights return self['weights'] unless self['capsules'] capsules.values.each_with_object({}) do |cap, acc| cap['weights'].each { |q, w| acc[q] = w } end end |