Class: Sidekiq::JobSet

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

Direct Known Subclasses

DeadSet, RetrySet, ScheduledSet

Instance Attribute Summary

Attributes inherited from SortedSet

#name

Instance Method Summary collapse

Methods inherited from SortedSet

#clear, #initialize, #size

Constructor Details

This class inherits a constructor from Sidekiq::SortedSet

Instance Method Details

#delete_by_jid(score, jid) ⇒ Object Also known as: delete



534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/sidekiq/api.rb', line 534

def delete_by_jid(score, jid)
  Sidekiq.redis do |conn|
    elements = conn.zrangebyscore(name, score, score)
    elements.each do |element|
      message = Sidekiq.load_json(element)
      if message["jid"] == jid
        ret = conn.zrem(name, element)
        @_size -= 1 if ret
        break ret
      end
      false
    end
  end
end

#delete_by_value(name, value) ⇒ Object



526
527
528
529
530
531
532
# File 'lib/sidekiq/api.rb', line 526

def delete_by_value(name, value)
  Sidekiq.redis do |conn|
    ret = conn.zrem(name, value)
    @_size -= 1 if ret
    ret
  end
end

#eachObject



485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/sidekiq/api.rb', line 485

def each
  initial_size = @_size
  offset_size = 0
  page = -1
  page_size = 50

  loop do
    range_start = page * page_size + offset_size
    range_end   = page * page_size + offset_size + (page_size - 1)
    elements = Sidekiq.redis do |conn|
      conn.zrange name, range_start, range_end, with_scores: true
    end
    break if elements.empty?
    page -= 1
    elements.each do |element, score|
      yield SortedEntry.new(self, score, element)
    end
    offset_size = initial_size - @_size
  end
end

#fetch(score, jid = nil) ⇒ Object



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/sidekiq/api.rb', line 506

def fetch(score, jid = nil)
  elements = Sidekiq.redis do |conn|
    conn.zrangebyscore(name, score, score)
  end

  elements.inject([]) do |result, element|
    entry = SortedEntry.new(self, score, element)
    if jid
      result << entry if entry.jid == jid
    else
      result << entry
    end
    result
  end
end

#find_job(jid) ⇒ Object



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

def find_job(jid)
  self.detect { |j| j.jid == jid }
end

#schedule(timestamp, message) ⇒ Object



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

def schedule(timestamp, message)
  Sidekiq.redis do |conn|
    conn.zadd(name, timestamp.to_f.to_s, Sidekiq.dump_json(message))
  end
end