Sha256: a7938a63df08fc1462d260218e85e8a3cf697d576e32f1392e98385b63628b1c

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

module MultiWorker
  module Adapters
    class Sidekiq
      def self.configure(base, opts={})
        base.class_eval do
          if opts[:status]
            require 'sidekiq_status'
            include ::SidekiqStatus::Worker
          else
            include ::Sidekiq::Worker
          end
          
          @sidekiq_options = ::Sidekiq.default_worker_options.symbolize_keys
          @sidekiq_options.merge! :queue => opts[:queue]

          if opts.has_key?(:backtrace)
            @sidekiq_options.merge! :backtrace => opts[:backtrace]
          end

          if opts.has_key?(:retry)
            @retry = opts[:retry]
            case @retry
            when Hash
              @sidekiq_options.merge!(:retry => @retry[:limit])
              sidekiq_retry_in(&@retry[:delay])
            when true, false, Fixnum
              @sidekiq_options.merge!(:retry => @retry)
            end
          end

          if opts[:lock]
            require 'sidekiq-lock'
            include ::Sidekiq::Lock::Worker

            @sidekiq_options.merge!(:lock => opts[:lock])
          end

          if opts[:unique]
            require "sidekiq-unique-jobs"
            @sidekiq_options.merge!(:unique => true)
          end

          sidekiq_options @sidekiq_options

          def self.perform(*args)
            self.new.perform(*args)
          end

          def perform_async(*args)
            self.class.perform_async(*args)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
multi_worker-0.1.0 lib/multi_worker/adapters/sidekiq.rb