Class: Sidekiq::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/api.rb

Overview

Sidekiq::Process represents an active Sidekiq process talking with Redis. Each process has a set of attributes which look like this:

{ 'hostname' => 'app-1.example.com', 'started_at' => , 'pid' => 12345, 'tag' => 'myapp' 'concurrency' => 5, 'capsules' => => {"mode" => "weighted", "concurrency" => 5, "weights" => {"default" => 2, "low" => 1}}, 'busy' => 3, 'beat' => , 'identity' => , 'embedded' => true, }

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Process

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



1126
1127
1128
# File 'lib/sidekiq/api.rb', line 1126

def initialize(hash)
  @attribs = hash
end

Instance Method Details

#[](key) ⇒ Object



1138
1139
1140
# File 'lib/sidekiq/api.rb', line 1138

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

#capsulesObject



1174
1175
1176
# File 'lib/sidekiq/api.rb', line 1174

def capsules
  self["capsules"]
end

#dump_threadsObject

Signal this process to log backtraces for all threads. Useful if you have a frozen or deadlocked process which is still sending a heartbeat. This method is asynchronous and it can take 5-10 seconds.



1210
1211
1212
# File 'lib/sidekiq/api.rb', line 1210

def dump_threads
  signal("TTIN")
end

#embedded?Boolean

Returns:

  • (Boolean)


1182
1183
1184
# File 'lib/sidekiq/api.rb', line 1182

def embedded?
  self["embedded"]
end

#identityObject Also known as: id



1142
1143
1144
# File 'lib/sidekiq/api.rb', line 1142

def identity
  self["identity"]
end

#labelsObject



1134
1135
1136
# File 'lib/sidekiq/api.rb', line 1134

def labels
  self["labels"].to_a
end

#leader?Boolean

Returns:

  • (Boolean)


1219
1220
1221
# File 'lib/sidekiq/api.rb', line 1219

def leader?
  Sidekiq.redis { |c| c.get("dear-leader") == identity }
end

#queuesObject

deprecated, use capsules below



1148
1149
1150
1151
1152
1153
1154
1155
# File 'lib/sidekiq/api.rb', line 1148

def queues
  # Backwards compatibility with <8.0.8
  if !self["capsules"]
    self["queues"]
  else
    capsules.values.flat_map { |x| x["weights"].keys }.uniq
  end
end

#quiet!Object

Signal this process to stop processing new jobs. It will continue to execute jobs it has already fetched. This method is asynchronous and it can take 5-10 seconds for the process to quiet.



1190
1191
1192
1193
1194
# File 'lib/sidekiq/api.rb', line 1190

def quiet!
  raise "Can't quiet an embedded process" if embedded?

  signal("TSTP")
end

#stop!Object

Signal this process to shutdown. It will shutdown within its configured :timeout value, default 25 seconds. This method is asynchronous and it can take 5-10 seconds for the process to start shutting down.



1200
1201
1202
1203
1204
# File 'lib/sidekiq/api.rb', line 1200

def stop!
  raise "Can't stop an embedded process" if embedded?

  signal("TERM")
end

#stopping?Boolean

Returns true if this process is quiet or shutting down.

Returns:

  • (Boolean)

    true if this process is quiet or shutting down



1215
1216
1217
# File 'lib/sidekiq/api.rb', line 1215

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

#tagObject



1130
1131
1132
# File 'lib/sidekiq/api.rb', line 1130

def tag
  self["tag"]
end

#versionObject



1178
1179
1180
# File 'lib/sidekiq/api.rb', line 1178

def version
  self["version"]
end

#weightsObject

deprecated, use capsules below



1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
# File 'lib/sidekiq/api.rb', line 1158

def weights
  # Backwards compatibility with <8.0.8
  if !self["capsules"]
    self["weights"]
  else
    hash = {}
    capsules.values.each do |cap|
      # Note: will lose data if two capsules are processing the same named queue
      cap["weights"].each_pair do |queue, weight|
        hash[queue] = weight
      end
    end
    hash
  end
end