Class: Sidekiq::JobRecord
- Inherits:
-
Object
- Object
- Sidekiq::JobRecord
- Defined in:
- lib/sidekiq/api.rb
Overview
Represents a pending job within a Sidekiq queue.
The job should be considered immutable but may be removed from the queue via JobRecord#delete.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
the parsed Hash of job data.
-
#Item ⇒ Object
readonly
the parsed Hash of job data.
-
#queue ⇒ Object
readonly
the queue associated with this job.
-
#Queue ⇒ Object
readonly
the queue associated with this job.
-
#Value ⇒ Object
readonly
the underlying String in Redis.
-
#value ⇒ Object
readonly
the underlying String in Redis.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Access arbitrary attributes within the job hash.
- #args ⇒ Object
- #bid ⇒ Object
- #created_at ⇒ Object
-
#delete ⇒ Object
Remove this job from the queue.
- #display_args ⇒ Object
- #display_class ⇒ Object
- #enqueued_at ⇒ Object
- #error_backtrace ⇒ Object
- #jid ⇒ Object
-
#klass ⇒ Object
This is the job class which Sidekiq will execute.
- #latency ⇒ Object
- #tags ⇒ Object
Instance Attribute Details
#item ⇒ Object (readonly)
the parsed Hash of job data
335 336 337 |
# File 'lib/sidekiq/api.rb', line 335 def item @item end |
#Item ⇒ Object (readonly)
the parsed Hash of job data
335 |
# File 'lib/sidekiq/api.rb', line 335 attr_reader :item |
#queue ⇒ Object (readonly)
the queue associated with this job
341 342 343 |
# File 'lib/sidekiq/api.rb', line 341 def queue @queue end |
#Queue ⇒ Object (readonly)
the queue associated with this job
341 |
# File 'lib/sidekiq/api.rb', line 341 attr_reader :queue |
#Value ⇒ Object (readonly)
the underlying String in Redis
338 |
# File 'lib/sidekiq/api.rb', line 338 attr_reader :value |
#value ⇒ Object (readonly)
the underlying String in Redis
338 339 340 |
# File 'lib/sidekiq/api.rb', line 338 def value @value end |
Instance Method Details
#[](name) ⇒ Object
Access arbitrary attributes within the job hash
458 459 460 461 462 463 |
# File 'lib/sidekiq/api.rb', line 458 def [](name) # nil will happen if the JSON fails to parse. # We don't guarantee Sidekiq will work with bad job JSON but we should # make a best effort to minimize the damage. @item ? @item[name] : nil end |
#args ⇒ Object
410 411 412 |
# File 'lib/sidekiq/api.rb', line 410 def args @args || @item["args"] end |
#bid ⇒ Object
418 419 420 |
# File 'lib/sidekiq/api.rb', line 418 def bid self["bid"] end |
#created_at ⇒ Object
426 427 428 |
# File 'lib/sidekiq/api.rb', line 426 def created_at Time.at(self["created_at"] || self["enqueued_at"] || 0).utc end |
#delete ⇒ Object
Remove this job from the queue
450 451 452 453 454 455 |
# File 'lib/sidekiq/api.rb', line 450 def delete count = Sidekiq.redis { |conn| conn.lrem("queue:#{@queue}", 1, @value) } count != 0 end |
#display_args ⇒ Object
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/sidekiq/api.rb', line 388 def display_args # Unwrap known wrappers so they show up in a human-friendly manner in the Web UI @display_args ||= if klass == "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper" || klass == "Sidekiq::ActiveJob::Wrapper" job_args = self["wrapped"] ? deserialize_argument(args[0]["arguments"]) : [] if (self["wrapped"] || args[0]) == "ActionMailer::DeliveryJob" # remove MailerClass, mailer_method and 'deliver_now' job_args.drop(3) elsif (self["wrapped"] || args[0]) == "ActionMailer::MailDeliveryJob" # remove MailerClass, mailer_method and 'deliver_now' job_args.drop(3).first.values_at("params", "args") else job_args end else if self["encrypt"] # no point in showing 150+ bytes of random garbage args[-1] = "[encrypted data]" end args end end |
#display_class ⇒ Object
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/sidekiq/api.rb', line 371 def display_class # Unwrap known wrappers so they show up in a human-friendly manner in the Web UI @klass ||= self["display_class"] || begin if klass == "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper" || klass == "Sidekiq::ActiveJob::Wrapper" job_class = @item["wrapped"] || args[0] if job_class == "ActionMailer::DeliveryJob" || job_class == "ActionMailer::MailDeliveryJob" # MailerClass#mailer_method args[0]["arguments"][0..1].join("#") else job_class end else klass end end end |
#enqueued_at ⇒ Object
422 423 424 |
# File 'lib/sidekiq/api.rb', line 422 def enqueued_at self["enqueued_at"] ? Time.at(self["enqueued_at"]).utc : nil end |
#error_backtrace ⇒ Object
434 435 436 437 438 439 440 441 442 |
# File 'lib/sidekiq/api.rb', line 434 def error_backtrace # Cache nil values if defined?(@error_backtrace) @error_backtrace else value = self["error_backtrace"] @error_backtrace = value && uncompress_backtrace(value) end end |
#jid ⇒ Object
414 415 416 |
# File 'lib/sidekiq/api.rb', line 414 def jid self["jid"] end |
#klass ⇒ Object
This is the job class which Sidekiq will execute. If using ActiveJob, this class will be the ActiveJob adapter class rather than a specific job.
367 368 369 |
# File 'lib/sidekiq/api.rb', line 367 def klass self["class"] end |
#latency ⇒ Object
444 445 446 447 |
# File 'lib/sidekiq/api.rb', line 444 def latency now = Time.now.to_f now - (@item["enqueued_at"] || @item["created_at"] || now) end |
#tags ⇒ Object
430 431 432 |
# File 'lib/sidekiq/api.rb', line 430 def self["tags"] || [] end |