Class: AtomicSidekiq::AtomicFetch

Inherits:
Object
  • Object
show all
Defined in:
lib/atomic_sidekiq/atomic_fetch.rb

Constant Summary collapse

IN_FLIGHT_KEY_PREFIX =
"flight".freeze
DEFAULT_POLL_INTERVAL =

seconds

5
DEFAULT_EXPIRATION_TIME =

seconds

3600
DEFAULT_COLLECTION_INTERVAL =

seconds

60

Instance Method Summary collapse

Constructor Details

#initialize(options, in_flight_keymaker: nil) ⇒ AtomicFetch

Returns a new instance of AtomicFetch.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/atomic_sidekiq/atomic_fetch.rb', line 9

def initialize(options, in_flight_keymaker: nil)
  @keymaker = in_flight_keymaker ||
              InFlightKeymaker.new(IN_FLIGHT_KEY_PREFIX)

  @retrieve_op = AtomicOperation::Retrieve.new(
    in_flight_keymaker: keymaker
  )

  @queues ||= options[:queues].map { |q| "queue:#{q}" }
  @strictly_ordered_queues = !!options[:strict]
  @@next_collection ||= Time.now

  configure_atomic_fetch(options.fetch(:atomic_fetch, {}))
end

Instance Method Details

#retrieve_workObject



24
25
26
27
28
29
30
31
# File 'lib/atomic_sidekiq/atomic_fetch.rb', line 24

def retrieve_work
  collect_dead_jobs!
  work = retrieve_op.perform(ordered_queues, expire_at)
  return UnitOfWork.new(*work, in_flight_keymaker: keymaker) if work

  sleep(poll_interval)
  nil
end