Class: Sidekiq::Job
- Inherits:
-
Object
- Object
- Sidekiq::Job
- Defined in:
- lib/sidekiq/api.rb
Overview
Encapsulates a pending job within a Sidekiq queue or sorted set.
The job should be considered immutable but may be removed from the queue via Job#delete.
Direct Known Subclasses
Constant Summary collapse
- KNOWN_WRAPPERS =
[/\ASidekiq::Extensions::Delayed/, "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper"]
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #args ⇒ Object
-
#delete ⇒ Object
Remove this job from the queue.
- #display_args ⇒ Object
- #display_class ⇒ Object
- #enqueued_at ⇒ Object
-
#initialize(item, queue_name = nil) ⇒ Job
constructor
A new instance of Job.
- #jid ⇒ Object
- #klass ⇒ Object
- #latency ⇒ Object
- #queue ⇒ Object
Constructor Details
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the value of attribute item.
193 194 195 |
# File 'lib/sidekiq/api.rb', line 193 def item @item end |
Instance Method Details
#[](name) ⇒ Object
262 263 264 |
# File 'lib/sidekiq/api.rb', line 262 def [](name) @item.__send__(:[], name) end |
#args ⇒ Object
233 234 235 |
# File 'lib/sidekiq/api.rb', line 233 def args @item['args'] end |
#delete ⇒ Object
Remove this job from the queue.
255 256 257 258 259 260 |
# File 'lib/sidekiq/api.rb', line 255 def delete count = Sidekiq.redis do |conn| conn.lrem("queue:#{@queue}", 1, @value) end count != 0 end |
#display_args ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/sidekiq/api.rb', line 219 def display_args # Unwrap known wrappers so they show up in a human-friendly manner in the Web UI @args ||= case klass when /\ASidekiq::Extensions::Delayed/ safe_load(args[0], args) do |_, _, arg| arg end when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper" args[1..-1] else args end end |
#display_class ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/sidekiq/api.rb', line 205 def display_class # Unwrap known wrappers so they show up in a human-friendly manner in the Web UI @klass ||= case klass when /\ASidekiq::Extensions::Delayed/ safe_load(args[0], klass) do |target, method, _| "#{target}.#{method}" end when "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper" args[0] else klass end end |
#enqueued_at ⇒ Object
241 242 243 |
# File 'lib/sidekiq/api.rb', line 241 def enqueued_at Time.at(@item['enqueued_at'] || 0).utc end |
#jid ⇒ Object
237 238 239 |
# File 'lib/sidekiq/api.rb', line 237 def jid @item['jid'] end |
#klass ⇒ Object
201 202 203 |
# File 'lib/sidekiq/api.rb', line 201 def klass @item['class'] end |
#latency ⇒ Object
249 250 251 |
# File 'lib/sidekiq/api.rb', line 249 def latency Time.now.to_f - @item['enqueued_at'] end |
#queue ⇒ Object
245 246 247 |
# File 'lib/sidekiq/api.rb', line 245 def queue @queue end |