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-leaderSTRING. -
#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.
164 165 166 |
# File 'lib/wurk/process_set.rb', line 164 def initialize(hash) @attribs = hash end |
Instance Method Details
#[](key) ⇒ Object
170 |
# File 'lib/wurk/process_set.rb', line 170 def [](key) = @attribs[key] |
#capsules ⇒ Object
196 |
# File 'lib/wurk/process_set.rb', line 196 def capsules = self['capsules'] |
#dump_threads ⇒ Object
SIGTTIN — dump every thread's backtrace. For diagnosing frozen processes that are still beating.
217 218 219 |
# File 'lib/wurk/process_set.rb', line 217 def dump_threads signal('TTIN') end |
#embedded? ⇒ Boolean
198 |
# File 'lib/wurk/process_set.rb', line 198 def = self['embedded'] |
#identity ⇒ Object Also known as: id
171 |
# File 'lib/wurk/process_set.rb', line 171 def identity = self['identity'] |
#labels ⇒ Object
169 |
# File 'lib/wurk/process_set.rb', line 169 def labels = self['labels'].to_a |
#leader? ⇒ Boolean
Compares identity against the dear-leader STRING. Ent-only;
always false in OSS/free.
230 231 232 |
# File 'lib/wurk/process_set.rb', line 230 def leader? Wurk.redis(idempotent: true) { |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.
177 178 179 180 181 182 183 |
# File 'lib/wurk/process_set.rb', line 177 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.
202 203 204 205 206 |
# File 'lib/wurk/process_set.rb', line 202 def quiet! raise 'Cannot quiet an embedded process' if signal('TSTP') end |
#stop! ⇒ Object
SIGTERM — graceful shutdown within shutdown_timeout. Asynchronous.
209 210 211 212 213 |
# File 'lib/wurk/process_set.rb', line 209 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.
224 225 226 |
# File 'lib/wurk/process_set.rb', line 224 def stopping? self['quiet'] == 'true' end |
#tag ⇒ Object
168 |
# File 'lib/wurk/process_set.rb', line 168 def tag = self['tag'] |
#version ⇒ Object
197 |
# File 'lib/wurk/process_set.rb', line 197 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.
188 189 190 191 192 193 194 |
# File 'lib/wurk/process_set.rb', line 188 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 |