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
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #args ⇒ Object
- #created_at ⇒ 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.
280 281 282 |
# File 'lib/sidekiq/api.rb', line 280 def item @item end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
281 282 283 |
# File 'lib/sidekiq/api.rb', line 281 def value @value end |
Instance Method Details
#[](name) ⇒ Object
366 367 368 |
# File 'lib/sidekiq/api.rb', line 366 def [](name) @item[name] end |
#args ⇒ Object
333 334 335 |
# File 'lib/sidekiq/api.rb', line 333 def args @item['args'] end |
#created_at ⇒ Object
345 346 347 |
# File 'lib/sidekiq/api.rb', line 345 def created_at Time.at(@item['created_at'] || @item['enqueued_at'] || 0).utc end |
#delete ⇒ Object
Remove this job from the queue.
359 360 361 362 363 364 |
# File 'lib/sidekiq/api.rb', line 359 def delete count = Sidekiq.redis do |conn| conn.lrem("queue:#{@queue}", 1, @value) end count != 0 end |
#display_args ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/sidekiq/api.rb', line 313 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" job_args = @item['wrapped'] ? args[0]["arguments"] : [] if 'ActionMailer::DeliveryJob' == (@item['wrapped'] || args[0]) # remove MailerClass, mailer_method and 'deliver_now' job_args.drop(3) else job_args end else args end end |
#display_class ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/sidekiq/api.rb', line 293 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" job_class = @item['wrapped'] || args[0] if 'ActionMailer::DeliveryJob' == job_class # MailerClass#mailer_method args[0]['arguments'][0..1].join('#') else job_class end else klass end end |
#enqueued_at ⇒ Object
341 342 343 |
# File 'lib/sidekiq/api.rb', line 341 def enqueued_at @item['enqueued_at'] ? Time.at(@item['enqueued_at']).utc : nil end |
#jid ⇒ Object
337 338 339 |
# File 'lib/sidekiq/api.rb', line 337 def jid @item['jid'] end |
#klass ⇒ Object
289 290 291 |
# File 'lib/sidekiq/api.rb', line 289 def klass @item['class'] end |
#latency ⇒ Object
353 354 355 |
# File 'lib/sidekiq/api.rb', line 353 def latency Time.now.to_f - (@item['enqueued_at'] || @item['created_at']) end |
#queue ⇒ Object
349 350 351 |
# File 'lib/sidekiq/api.rb', line 349 def queue @queue end |