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, #queue

Constructor Details

#initialize(parent, score, item) ⇒ SortedEntry

Returns a new instance of SortedEntry.



388
389
390
391
392
# File 'lib/sidekiq/api.rb', line 388

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

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



386
387
388
# File 'lib/sidekiq/api.rb', line 386

def parent
  @parent
end

#scoreObject (readonly)

Returns the value of attribute score.



385
386
387
# File 'lib/sidekiq/api.rb', line 385

def score
  @score
end

Instance Method Details

#add_to_queueObject



411
412
413
414
415
416
# File 'lib/sidekiq/api.rb', line 411

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

#atObject



394
395
396
# File 'lib/sidekiq/api.rb', line 394

def at
  Time.at(score).utc
end

#deleteObject



398
399
400
401
402
403
404
# File 'lib/sidekiq/api.rb', line 398

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

#killObject

Place job in the dead set



429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/sidekiq/api.rb', line 429

def kill
  raise 'Kill not available on jobs which have not failed' unless item['failed_at']
  remove_job do |message|
    Sidekiq.logger.info { "Killing job #{message['jid']}" }
    now = Time.now.to_f
    Sidekiq.redis do |conn|
      conn.multi do
        conn.zadd('dead', now, message)
        conn.zremrangebyscore('dead', '-inf', now - DeadSet.timeout)
        conn.zremrangebyrank('dead', 0, - DeadSet.max_jobs)
      end
    end
  end
end

#reschedule(at) ⇒ Object



406
407
408
409
# File 'lib/sidekiq/api.rb', line 406

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

#retryObject



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

def retry
  raise "Retry not available on jobs which have not failed" unless item["failed_at"]
  remove_job do |message|
    msg = Sidekiq.load_json(message)
    msg['retry_count'] -= 1
    Sidekiq::Client.push(msg)
  end
end