aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_job/queue_adapters/resque_adapter.rb
blob: 6686f10593849eb4a469d2e37a4b5f5a6421bd6a (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
require 'resque'
require 'active_support/core_ext/enumerable'
require 'active_support/core_ext/array/access'

module ActiveJob
  module QueueAdapters
    class ResqueAdapter
      class << self
        def queue(job, *args)
          Resque.enqueue JobWrapper.new(job), job, *args
        end
      end

      class JobWrapper
        class << self
          def perform(job_name, *args)
            job_name.constantize.new.perform *Parameters.deserialize(args)
          end
        end

        def initialize(job)
          @queue = job.queue_name
        end

        def to_s
          self.class.name
        end
      end
    end
  end
end