Module: Sidekiq::LimitFetch

Extended by:
LimitFetch
Included in:
LimitFetch
Defined in:
lib/sidekiq/limit_fetch.rb,
lib/sidekiq/limit_fetch/queues.rb,
lib/sidekiq/limit_fetch/instances.rb,
lib/sidekiq/limit_fetch/unit_of_work.rb,
lib/sidekiq/limit_fetch/global/monitor.rb,
lib/sidekiq/limit_fetch/global/selector.rb,
lib/sidekiq/limit_fetch/global/semaphore.rb

Defined Under Namespace

Modules: Global, Instances, Queues Classes: UnitOfWork

Constant Summary collapse

TIMEOUT =
Sidekiq::BasicFetch::TIMEOUT
RedisBaseConnectionError =
post_7? ? RedisClient::ConnectionError : Redis::BaseConnectionError
RedisCommandError =
post_7? ? RedisClient::CommandError : Redis::CommandError

Instance Method Summary collapse

Instance Method Details

#bulk_requeue(*args) ⇒ Object

Backwards compatibility for sidekiq v6.1.0



52
53
54
55
56
57
58
# File 'lib/sidekiq/limit_fetch.rb', line 52

def bulk_requeue(*args)
  if Sidekiq::BasicFetch.respond_to?(:bulk_requeue) # < 6.1.0
    Sidekiq::BasicFetch.bulk_requeue(*args)
  else # 6.1.0+
    Sidekiq::BasicFetch.new(post_7? ? Sidekiq.default_configuration.default_capsule : config).bulk_requeue(*args)
  end
end

#configObject



45
46
47
48
# File 'lib/sidekiq/limit_fetch.rb', line 45

def config
  # Post 6.5, Sidekiq.options is deprecated and replaced with passing Sidekiq directly
  post_6_5? ? Sidekiq : Sidekiq.options
end

#new(_) ⇒ Object



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

def new(_)
  self
end

#post_6_5?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/sidekiq/limit_fetch.rb', line 28

def post_6_5?
  @post_6_5 ||= Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('6.5.0')
end

#post_7?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/sidekiq/limit_fetch.rb', line 24

def post_7?
  @post_7 ||= Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('7.0.0')
end

#redis_retryableObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sidekiq/limit_fetch.rb', line 60

def redis_retryable
  yield
rescue RedisBaseConnectionError
  sleep TIMEOUT
  retry
rescue RedisCommandError => e
  # If Redis was restarted and is still loading its snapshot,
  # then we should treat this as a temporary connection error too.
  raise unless e.message =~ /^LOADING/

  sleep TIMEOUT
  retry
end

#retrieve_workObject



39
40
41
42
43
# File 'lib/sidekiq/limit_fetch.rb', line 39

def retrieve_work
  queue, job = redis_brpop(Queues.acquire)
  Queues.release_except(queue)
  UnitOfWork.new(queue, job) if job
end