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
- #failed_at ⇒ Object
- #jid ⇒ Object
-
#klass ⇒ Object
This is the job class which Sidekiq will execute.
- #latency ⇒ Object
- #retried_at ⇒ Object
- #tags ⇒ Object
Instance Attribute Details
#item ⇒ Object (readonly)
the parsed Hash of job data
357 358 359 |
# File 'lib/sidekiq/api.rb', line 357 def item @item end |
#Item ⇒ Object (readonly)
the parsed Hash of job data
357 |
# File 'lib/sidekiq/api.rb', line 357 attr_reader :item |
#queue ⇒ Object (readonly)
the queue associated with this job
363 364 365 |
# File 'lib/sidekiq/api.rb', line 363 def queue @queue end |
#Queue ⇒ Object (readonly)
the queue associated with this job
363 |
# File 'lib/sidekiq/api.rb', line 363 attr_reader :queue |
#Value ⇒ Object (readonly)
the underlying String in Redis
360 |
# File 'lib/sidekiq/api.rb', line 360 attr_reader :value |
#value ⇒ Object (readonly)
the underlying String in Redis
360 361 362 |
# File 'lib/sidekiq/api.rb', line 360 def value @value end |
Instance Method Details
#[](name) ⇒ Object
Access arbitrary attributes within the job hash
503 504 505 506 507 508 |
# File 'lib/sidekiq/api.rb', line 503 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
432 433 434 |
# File 'lib/sidekiq/api.rb', line 432 def args @args || @item["args"] end |
#bid ⇒ Object
440 441 442 |
# File 'lib/sidekiq/api.rb', line 440 def bid self["bid"] end |
#created_at ⇒ Object
462 463 464 |
# File 'lib/sidekiq/api.rb', line 462 def created_at (self["created_at"] || self["enqueued_at"] || 0) end |
#delete ⇒ Object
Remove this job from the queue
495 496 497 498 499 500 |
# File 'lib/sidekiq/api.rb', line 495 def delete count = Sidekiq.redis { |conn| conn.lrem("queue:#{@queue}", 1, @value) } count != 0 end |
#display_args ⇒ Object
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/sidekiq/api.rb', line 410 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
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/sidekiq/api.rb', line 393 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
456 457 458 459 460 |
# File 'lib/sidekiq/api.rb', line 456 def enqueued_at if self["enqueued_at"] (self["enqueued_at"]) end end |
#error_backtrace ⇒ Object
470 471 472 473 474 475 476 477 478 |
# File 'lib/sidekiq/api.rb', line 470 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 |
#failed_at ⇒ Object
444 445 446 447 448 |
# File 'lib/sidekiq/api.rb', line 444 def failed_at if self["failed_at"] (self["failed_at"]) end end |
#jid ⇒ Object
436 437 438 |
# File 'lib/sidekiq/api.rb', line 436 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.
389 390 391 |
# File 'lib/sidekiq/api.rb', line 389 def klass self["class"] end |
#latency ⇒ Object
480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'lib/sidekiq/api.rb', line 480 def latency = @item["enqueued_at"] || @item["created_at"] if if .is_a?(Float) # old format Time.now.to_f - else (::Process.clock_gettime(::Process::CLOCK_REALTIME, :millisecond) - ) / 1000.0 end else 0.0 end end |
#retried_at ⇒ Object
450 451 452 453 454 |
# File 'lib/sidekiq/api.rb', line 450 def retried_at if self["retried_at"] (self["retried_at"]) end end |
#tags ⇒ Object
466 467 468 |
# File 'lib/sidekiq/api.rb', line 466 def self["tags"] || [] end |