Class: Wurk::SortedSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable, API::Fast::SortedSetExt
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

#nameObject (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



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

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

#clearObject

UNLINK over the whole set. Idempotent. Method name is Sidekiq wire-compat — ‘clear?` would break the alias.



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

def clear # rubocop:disable Naming/PredicateMethod
  Wurk.redis { |conn| conn.call('UNLINK', @name) }
  true
end

#scan(match, count = 100) {|String, Float| ... } ⇒ Object

Streams every (value, score) pair through ZSCAN. ‘match` is wrapped in `*` glob characters — callers pass a jid or class name fragment.

Yields:

  • (String, Float)

    raw JSON payload and its score.



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

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

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

#sizeObject

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