Sha256: 0d22bc59580741876f31363291790d943f7ecfff7b1a561abeadda22c2e44c1a

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

module CarrierWave
  module Backgrounder
    module Support
      module Backends

        def self.included(base)
          base.extend ClassMethods
        end

        module ClassMethods
          attr_reader :queue_options

          def backend(queue_name=nil, args={})
            return @backend if @backend
            @queue_options = args
            @backend = queue_name
          end

          def enqueue_for_backend(worker, class_name, subject_id, mounted_as)
            self.send :"enqueue_#{backend}", worker, class_name, subject_id, mounted_as
          end

          private

          def enqueue_active_job(worker, *args)
            worker.perform_later(*args.map(&:to_s))
          end

          def enqueue_sidekiq(worker, *args)
            override_queue_name = worker.sidekiq_options['queue'] == 'default' || worker.sidekiq_options['queue'].nil?
            args = sidekiq_queue_options(override_queue_name, 'class' => worker, 'args' => args.map(&:to_s))
            worker.client_push(args)
          end

          private

          def sidekiq_queue_options(override_queue_name, args)
            if override_queue_name && queue_options[:queue]
              args['queue'] = queue_options[:queue]
            end
            args['retry'] = queue_options[:retry] unless queue_options[:retry].nil?
            args['timeout'] = queue_options[:timeout] if queue_options[:timeout]
            args['backtrace'] = queue_options[:backtrace] if queue_options[:backtrace]
            args
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
carrierwave_backgrounder-1.0.2 lib/backgrounder/support/backends.rb
carrierwave_backgrounder-1.0.1 lib/backgrounder/support/backends.rb
carrierwave_backgrounder-1.0.0 lib/backgrounder/support/backends.rb
carrierwave_backgrounder-1.0.0.beta.2 lib/backgrounder/support/backends.rb
carrierwave_backgrounder-1.0.0.beta lib/backgrounder/support/backends.rb