Class: Roundhouse::Job
- Inherits:
-
Object
- Object
- Roundhouse::Job
- Defined in:
- lib/roundhouse/api.rb
Overview
Encapsulates a pending job within a Roundhouse 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.
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_id ⇒ Object
Constructor Details
#initialize(item, queue_name = nil) ⇒ Job
Returns a new instance of Job.
320 321 322 323 324 |
# File 'lib/roundhouse/api.rb', line 320 def initialize(item, queue_name=nil) @value = item @item = item.is_a?(Hash) ? item : Roundhouse.load_json(item) @queue_id = queue_name || @item['queue_id'] end |
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the value of attribute item.
318 319 320 |
# File 'lib/roundhouse/api.rb', line 318 def item @item end |
Instance Method Details
#[](name) ⇒ Object
391 392 393 |
# File 'lib/roundhouse/api.rb', line 391 def [](name) @item.__send__(:[], name) end |
#args ⇒ Object
358 359 360 |
# File 'lib/roundhouse/api.rb', line 358 def args @item['args'] end |
#created_at ⇒ Object
370 371 372 |
# File 'lib/roundhouse/api.rb', line 370 def created_at Time.at(@item['created_at'] || @item['enqueued_at'] || 0).utc end |
#delete ⇒ Object
Remove this job from the queue.
384 385 386 387 388 389 |
# File 'lib/roundhouse/api.rb', line 384 def delete count = Roundhouse.redis do |conn| conn.lrem("#{Roundhouse::Monitor::QUEUE}:#{@queue_id}", 1, @value) end count != 0 end |
#display_args ⇒ Object
344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/roundhouse/api.rb', line 344 def display_args # Unwrap known wrappers so they show up in a human-friendly manner in the Web UI @args ||= case klass when /\ARoundhouse::Extensions::Delayed/ safe_load(args[0], args) do |_, _, arg| arg end when "ActiveJob::QueueAdapters::RoundhouseAdapter::JobWrapper" @item['wrapped'] ? args[0]["arguments"] : [] else args end end |
#display_class ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/roundhouse/api.rb', line 330 def display_class # Unwrap known wrappers so they show up in a human-friendly manner in the Web UI @klass ||= case klass when /\ARoundhouse::Extensions::Delayed/ safe_load(args[0], klass) do |target, method, _| "#{target}.#{method}" end when "ActiveJob::QueueAdapters::RoundhouseAdapter::JobWrapper" @item['wrapped'] || args[0] else klass end end |
#enqueued_at ⇒ Object
366 367 368 |
# File 'lib/roundhouse/api.rb', line 366 def enqueued_at @item['enqueued_at'] ? Time.at(@item['enqueued_at']).utc : nil end |
#jid ⇒ Object
362 363 364 |
# File 'lib/roundhouse/api.rb', line 362 def jid @item['jid'] end |
#klass ⇒ Object
326 327 328 |
# File 'lib/roundhouse/api.rb', line 326 def klass @item['class'] end |
#latency ⇒ Object
378 379 380 |
# File 'lib/roundhouse/api.rb', line 378 def latency Time.now.to_f - (@item['enqueued_at'] || @item['created_at']) end |
#queue_id ⇒ Object
374 375 376 |
# File 'lib/roundhouse/api.rb', line 374 def queue_id @queue_id end |