Class: Sidekiq::SortedEntry

Inherits:
Job
  • Object
show all
Defined in:
lib/sidekiq/api.rb

Instance Attribute Summary collapse

Attributes inherited from Job

#item, #queue, #value

Instance Method Summary collapse

Methods inherited from Job

#[], #args, #created_at, #display_args, #display_class, #enqueued_at, #error_backtrace, #jid, #klass, #latency, #parse, #tags

Constructor Details

#initialize(parent, score, item) ⇒ SortedEntry

Returns a new instance of SortedEntry.



461
462
463
464
465
# File 'lib/sidekiq/api.rb', line 461

def initialize(parent, score, item)
  super(item)
  @score = score
  @parent = parent
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



459
460
461
# File 'lib/sidekiq/api.rb', line 459

def parent
  @parent
end

#scoreObject (readonly)

Returns the value of attribute score.



458
459
460
# File 'lib/sidekiq/api.rb', line 458

def score
  @score
end

Instance Method Details

#add_to_queueObject



485
486
487
488
489
490
# File 'lib/sidekiq/api.rb', line 485

def add_to_queue
  remove_job do |message|
    msg = Sidekiq.load_json(message)
    Sidekiq::Client.push(msg)
  end
end

#atObject



467
468
469
# File 'lib/sidekiq/api.rb', line 467

def at
  Time.at(score).utc
end

#deleteObject



471
472
473
474
475
476
477
# File 'lib/sidekiq/api.rb', line 471

def delete
  if @value
    @parent.delete_by_value(@parent.name, @value)
  else
    @parent.delete_by_jid(score, jid)
  end
end

#error?Boolean

Returns:

  • (Boolean)


508
509
510
# File 'lib/sidekiq/api.rb', line 508

def error?
  !!item["error_class"]
end

#killObject

Place job in the dead set



502
503
504
505
506
# File 'lib/sidekiq/api.rb', line 502

def kill
  remove_job do |message|
    DeadSet.new.kill(message)
  end
end

#reschedule(at) ⇒ Object



479
480
481
482
483
# File 'lib/sidekiq/api.rb', line 479

def reschedule(at)
  Sidekiq.redis do |conn|
    conn.zincrby(@parent.name, at - @score, Sidekiq.dump_json(@item))
  end
end

#retryObject



492
493
494
495
496
497
498
# File 'lib/sidekiq/api.rb', line 492

def retry
  remove_job do |message|
    msg = Sidekiq.load_json(message)
    msg["retry_count"] -= 1 if msg["retry_count"]
    Sidekiq::Client.push(msg)
  end
end