Class: Sidekiq::SortedEntry

Inherits:
JobRecord show all
Defined in:
lib/sidekiq/api.rb

Instance Attribute Summary collapse

Attributes inherited from JobRecord

#item, #queue, #value

Instance Method Summary collapse

Methods inherited from JobRecord

#[], #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.



476
477
478
479
480
# File 'lib/sidekiq/api.rb', line 476

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

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



474
475
476
# File 'lib/sidekiq/api.rb', line 474

def parent
  @parent
end

#scoreObject (readonly)

Returns the value of attribute score.



473
474
475
# File 'lib/sidekiq/api.rb', line 473

def score
  @score
end

Instance Method Details

#add_to_queueObject



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

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

#atObject



482
483
484
# File 'lib/sidekiq/api.rb', line 482

def at
  Time.at(score).utc
end

#deleteObject



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

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

#error?Boolean

Returns:

  • (Boolean)


523
524
525
# File 'lib/sidekiq/api.rb', line 523

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

#killObject

Place job in the dead set



517
518
519
520
521
# File 'lib/sidekiq/api.rb', line 517

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

#reschedule(at) ⇒ Object



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

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

#retryObject



507
508
509
510
511
512
513
# File 'lib/sidekiq/api.rb', line 507

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