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.



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

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

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

#scoreObject (readonly)

Returns the value of attribute score.



440
441
442
# File 'lib/sidekiq/api.rb', line 440

def score
  @score
end

Instance Method Details

#add_to_queueObject



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

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

#atObject



449
450
451
# File 'lib/sidekiq/api.rb', line 449

def at
  Time.at(score).utc
end

#deleteObject



453
454
455
456
457
458
459
# File 'lib/sidekiq/api.rb', line 453

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

#error?Boolean

Returns:

  • (Boolean)


489
490
491
# File 'lib/sidekiq/api.rb', line 489

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

#killObject

Place job in the dead set



483
484
485
486
487
# File 'lib/sidekiq/api.rb', line 483

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

#reschedule(at) ⇒ Object



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

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

#retryObject



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

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