Module: Jumbotron::Scheduling::DetectIntegration

Defined in:
app/scheduling/jumbotron/scheduling/detect_integration.rb

Constant Summary collapse

SUPPORTED =
"Solid Queue, Sidekiq + Sidekiq-Cron"

Class Method Summary collapse

Class Method Details

.adapter_nameObject



20
21
22
23
24
25
26
27
# File 'app/scheduling/jumbotron/scheduling/detect_integration.rb', line 20

def adapter_name
  return ActiveJob::Base.queue_adapter_name.to_s.to_sym if ActiveJob::Base.respond_to?(:queue_adapter_name)

  configured = Rails.application.config.active_job.queue_adapter
  return configured.to_sym if configured.is_a?(Symbol)

  ActiveJob::Base.queue_adapter.class.name.to_s.demodulize.underscore.sub(/_adapter\z/, "").to_sym
end

.callObject



12
13
14
15
16
17
18
# File 'app/scheduling/jumbotron/scheduling/detect_integration.rb', line 12

def call
  name = adapter_name
  return Backends::SolidQueue.new if name == :solid_queue
  return sidekiq_backend! if name == :sidekiq

  raise_unsupported(name)
end

.raise_unsupported(name) ⇒ Object



38
39
40
41
42
# File 'app/scheduling/jumbotron/scheduling/detect_integration.rb', line 38

def raise_unsupported(name)
  raise UnsupportedIntegrationError,
        "Jumbotron recurring schedules cannot be materialized for ActiveJob adapter :#{name}. " \
        "Supported scheduling integrations: #{SUPPORTED}."
end

.sidekiq_backend!Object



29
30
31
32
33
34
35
36
# File 'app/scheduling/jumbotron/scheduling/detect_integration.rb', line 29

def sidekiq_backend!
  return Backends::SidekiqCron.new if defined?(::Sidekiq::Cron::Job)

  raise UnsupportedIntegrationError,
        "Jumbotron recurring schedules cannot be materialized for ActiveJob adapter :sidekiq " \
        "because no supported recurring scheduler is present. " \
        "Supported scheduling integrations: #{SUPPORTED}."
end