Sha256: 67f316aa58a7a740791ca8f4a128e1d7f57807e80a0e8fc517afc1f6cdfc540d

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module AdvancedSneakersActiveJob
  # Advanced Sneakers adapter allows to patch Sneakers with custom configuration.
  # It is useful when already have Sneakers workers running and you want to run ActiveJob Sneakers process with another options.
  class Configuration
    include ActiveSupport::Configurable

    DEFAULT_SNEAKERS_CONFIG = {
      exchange: 'activejob',
      handler: AdvancedSneakersActiveJob::Handler
    }.freeze

    config_accessor(:handle_unrouted_messages) { true } # create queue/binding and re-publish if message is unrouted
    config_accessor(:activejob_workers_strategy) { :include } # [:include, :exclude, :only]
    config_accessor(:delay_proc) { ->(timestamp) { (timestamp - Time.now.to_f).round } } # seconds
    config_accessor(:delayed_queue_prefix) { 'delayed' }
    config_accessor(:retry_delay_proc) { ->(count) { AdvancedSneakersActiveJob::EXPONENTIAL_BACKOFF[count] } } # seconds

    def sneakers
      custom_config = DEFAULT_SNEAKERS_CONFIG.deep_merge(config.sneakers || {})

      if custom_config[:amqp].present? & custom_config[:vhost].nil?
        custom_config[:vhost] = AMQ::Settings.parse_amqp_url(custom_config[:amqp]).fetch(:vhost, '/')
      end

      Sneakers::CONFIG.to_hash.deep_merge(custom_config)
    end

    def sneakers=(custom)
      config.sneakers = custom
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
advanced-sneakers-activejob-0.2.3 lib/advanced_sneakers_activejob/configuration.rb
advanced-sneakers-activejob-0.2.2 lib/advanced_sneakers_activejob/configuration.rb
advanced-sneakers-activejob-0.2.1 lib/advanced_sneakers_activejob/configuration.rb
advanced-sneakers-activejob-0.2.0 lib/advanced_sneakers_activejob/configuration.rb
advanced-sneakers-activejob-0.1.0 lib/advanced_sneakers_activejob/configuration.rb