Class: Wurk::SortedSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wurk/job_set.rb

Overview

Base class for the three Sidekiq-compatible sorted-set views over Redis (schedule, retry, dead). Splits responsibilities: SortedSet owns the generic ZSET reads/clear; JobSet owns the job-aware mutations (schedule/retry_all/kill_all and the JobRecord-yielding iteration).

Subclasses pick the key by passing it to super in initialize:

class RetrySet < JobSet ; def initialize ; super('retry') ; end ; end

Wire-compat: every Redis call below matches Sidekiq OSS exactly. Spec: docs/target/sidekiq-free.md ยง19.5.

Direct Known Subclasses

JobSet

Constant Summary collapse

PAGE_SIZE =

Page size for paged ZRANGE โ€” matches upstream so dashboards observing Redis traffic see the same query pattern.

50

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ SortedSet

Returns a new instance of SortedSet.



25
26
27
# File 'lib/wurk/job_set.rb', line 25

def initialize(name)
  @name = name.to_s
end

Instance Attribute Details

#name ⇒ Object (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/wurk/job_set.rb', line 23

def name
  @name
end

Instance Method Details

#as_json(_options = nil) ⇒ Object



60
# File 'lib/wurk/job_set.rb', line 60

def as_json(_options = nil) = { name: @name }

#clear ⇒ Object Also known as: ๐Ÿ’ฃ

UNLINK over the whole set. Idempotent. Method name is Sidekiq wire-compat โ€” clear? would break the alias.



54
55
56
57
# File 'lib/wurk/job_set.rb', line 54

def clear
  Wurk.redis { |conn| conn.call('UNLINK', @name) }
  true
end

#scan(match, count = 100) ⇒ Object

ZSCAN, yielding a SortedEntry per match. match is wrapped in * glob characters unless it already carries one โ€” callers pass a jid or class name fragment, or their own pattern.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/wurk/job_set.rb', line 37

def scan(match, count = 100)
  return enum_for(:scan, match, count) unless block_given?

  match = match.to_s
  pattern = match.include?('*') ? match : "*#{match}*"
  cursor = '0'
  Wurk.redis do |conn|
    loop do
      cursor, pairs = conn.call('ZSCAN', @name, cursor, 'MATCH', pattern, 'COUNT', count)
      pairs.each_slice(2) { |value, score| yield SortedEntry.new(self, score, value) }
      break if cursor == '0'
    end
  end
end

#size ⇒ Object

ZCARD. O(1) on Redis side.



30
31
32
# File 'lib/wurk/job_set.rb', line 30

def size
  Wurk.redis { |conn| conn.call('ZCARD', @name) }
end