Class: Sidekiq::SortedEntry

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

Instance Attribute Summary collapse

Attributes inherited from Job

#item, #value

Instance Method Summary collapse

Methods inherited from Job

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

Constructor Details

#initialize(parent, score, item) ⇒ SortedEntry

Returns a new instance of SortedEntry.



418
419
420
421
422
# File 'lib/sidekiq/api.rb', line 418

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

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



416
417
418
# File 'lib/sidekiq/api.rb', line 416

def parent
  @parent
end

#scoreObject (readonly)

Returns the value of attribute score.



415
416
417
# File 'lib/sidekiq/api.rb', line 415

def score
  @score
end

Instance Method Details

#add_to_queueObject



441
442
443
444
445
446
# File 'lib/sidekiq/api.rb', line 441

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

#atObject



424
425
426
# File 'lib/sidekiq/api.rb', line 424

def at
  Time.at(score).utc
end

#deleteObject



428
429
430
431
432
433
434
# File 'lib/sidekiq/api.rb', line 428

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

#error?Boolean

Returns:

  • (Boolean)


464
465
466
# File 'lib/sidekiq/api.rb', line 464

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

#killObject

Place job in the dead set



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

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

#reschedule(at) ⇒ Object



436
437
438
439
# File 'lib/sidekiq/api.rb', line 436

def reschedule(at)
  delete
  @parent.schedule(at, item)
end

#retryObject



448
449
450
451
452
453
454
# File 'lib/sidekiq/api.rb', line 448

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