aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_job/job_wrappers/resque_wrapper.rb
blob: c34ea99f3c351a9137ef432b0f81fc432f191751 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'resque'

require 'active_support/core_ext/enumerable'
require 'active_support/core_ext/array/access'
require 'active_support/core_ext/string/inflections'


module ActiveJob
  module JobWrappers
    class ResqueWrapper
      class << self
        def wrap(job, args)
          [ new(job), *args.prepend(job) ]
        end

        def perform(*args)
          unwrapped_job = args.first.constantize
          
          if args.many?
            unwrapped_job.perform *args.from(1)
          else
            unwrapped_job.perform
          end
        end
      end


      def initialize(job)
        @queue = job.queue_name
      end
      
      def to_s
        self.class.to_s
      end
    end
  end
end