Class: Sidekiq::InterruptedSet

Inherits:
JobSet
  • Object
show all
Defined in:
lib/sidekiq/interrupted_set.rb

Constant Summary collapse

DEFAULT_MAX_CAPACITY =
10_000
DEFAULT_MAX_TIMEOUT =

3 months

90 * 24 * 60 * 60

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInterruptedSet

Returns a new instance of InterruptedSet.



8
9
10
# File 'lib/sidekiq/interrupted_set.rb', line 8

def initialize
  super "interrupted"
end

Class Method Details

.max_jobsObject



39
40
41
# File 'lib/sidekiq/interrupted_set.rb', line 39

def self.max_jobs
  Sidekiq.options[:interrupted_max_jobs] || DEFAULT_MAX_CAPACITY
end

.timeoutObject



43
44
45
# File 'lib/sidekiq/interrupted_set.rb', line 43

def self.timeout
  Sidekiq.options[:interrupted_timeout_in_seconds] || DEFAULT_MAX_TIMEOUT
end

Instance Method Details

#put(message, opts = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sidekiq/interrupted_set.rb', line 12

def put(message, opts = {})
  now = Time.now.to_f

  with_multi_connection(opts[:connection]) do |conn|
    conn.zadd(name, now.to_s, message)
    conn.zremrangebyscore(name, '-inf', now - self.class.timeout)
    conn.zremrangebyrank(name, 0, - self.class.max_jobs)
  end

  true
end

#retry_allObject



35
36
37
# File 'lib/sidekiq/interrupted_set.rb', line 35

def retry_all
  each(&:retry) while size > 0
end

#with_multi_connection(conn, &block) ⇒ Object

Yield block inside an existing multi connection or creates new one



25
26
27
28
29
30
31
32
33
# File 'lib/sidekiq/interrupted_set.rb', line 25

def with_multi_connection(conn, &block)
  return yield(conn) if conn

  Sidekiq.redis do |c|
    c.multi do |multi|
      yield(multi)
    end
  end
end