Sha256: 35addf6dc666b501468a519c69d6a27363d8dbb995925ec0a503eeb11283d684

Contents?: true

Size: 1.56 KB

Versions: 8

Compression:

Stored size: 1.56 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

    config_accessor(:publish_connection)
    config_accessor(:republish_connection)

    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

    def publisher_config
      sneakers.merge(publish_connection: publish_connection, republish_connection: republish_connection)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
advanced-sneakers-activejob-0.4.0 lib/advanced_sneakers_activejob/configuration.rb
advanced-sneakers-activejob-0.3.6 lib/advanced_sneakers_activejob/configuration.rb
advanced-sneakers-activejob-0.3.5 lib/advanced_sneakers_activejob/configuration.rb
advanced-sneakers-activejob-0.3.4 lib/advanced_sneakers_activejob/configuration.rb
advanced-sneakers-activejob-0.3.3 lib/advanced_sneakers_activejob/configuration.rb
advanced-sneakers-activejob-0.3.2 lib/advanced_sneakers_activejob/configuration.rb
advanced-sneakers-activejob-0.3.1 lib/advanced_sneakers_activejob/configuration.rb
advanced-sneakers-activejob-0.3.0 lib/advanced_sneakers_activejob/configuration.rb