Class: Wurk::Process

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(hash) ⇒ Process

Returns a new instance of Process.



171
172
173
# File 'lib/wurk/process_set.rb', line 171

def initialize(hash)
  @attribs = hash
end

Instance Method Details

#[](key) ⇒ Object



177
# File 'lib/wurk/process_set.rb', line 177

def [](key)  = @attribs[key]

#capsules ⇒ Object



203
# File 'lib/wurk/process_set.rb', line 203

def capsules  = self['capsules']

#dump_threads ⇒ Object

SIGTTIN — dump every thread's backtrace. For diagnosing frozen processes that are still beating.



224
225
226
# File 'lib/wurk/process_set.rb', line 224

def dump_threads
  signal('TTIN')
end

#embedded? ⇒ Boolean

Returns:

  • (Boolean)


205
# File 'lib/wurk/process_set.rb', line 205

def embedded? = self['embedded']

#identity ⇒ Object Also known as: id



178
# File 'lib/wurk/process_set.rb', line 178

def identity = self['identity']

#labels ⇒ Object



176
# File 'lib/wurk/process_set.rb', line 176

def labels   = self['labels'].to_a

#leader? ⇒ Boolean

Compares identity against the dear-leader STRING. Ent-only; always false in OSS/free.

Returns:

  • (Boolean)


237
238
239
# File 'lib/wurk/process_set.rb', line 237

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.



184
185
186
187
188
189
190
# File 'lib/wurk/process_set.rb', line 184

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.



209
210
211
212
213
# File 'lib/wurk/process_set.rb', line 209

def quiet!
  raise 'Cannot quiet an embedded process' if embedded?

  signal('TSTP')
end

#stop! ⇒ Object

SIGTERM — graceful shutdown within shutdown_timeout. Asynchronous.



216
217
218
219
220
# File 'lib/wurk/process_set.rb', line 216

def stop!
  raise 'Cannot stop an embedded process' if embedded?

  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.

Returns:

  • (Boolean)


231
232
233
# File 'lib/wurk/process_set.rb', line 231

def stopping?
  self['quiet'] == 'true'
end

#tag ⇒ Object



175
# File 'lib/wurk/process_set.rb', line 175

def tag      = self['tag']

#version ⇒ Object



204
# File 'lib/wurk/process_set.rb', line 204

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.



195
196
197
198
199
200
201
# File 'lib/wurk/process_set.rb', line 195

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