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.



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]

#capsulesObject



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

def capsules  = self['capsules']

#dump_threadsObject

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

Returns:

  • (Boolean)


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

def embedded? = self['embedded']

#identityObject Also known as: id



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

def identity = self['identity']

#labelsObject



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.

Returns:

  • (Boolean)


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

def leader?
  Wurk.redis { |c| c.call('GET', 'dear-leader') == identity }
end

#queuesObject

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 embedded?

  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 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)


219
220
221
# File 'lib/wurk/process_set.rb', line 219

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

#tagObject



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

def tag      = self['tag']

#versionObject



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

def version   = self['version']

#weightsObject

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