aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib/active_job/queue_adapters/sneakers_adapter.rb
blob: 60633639f4328f5f8a1ddb18a4fadb160d00bae3 (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
require 'sneakers'
require 'thread'

module ActiveJob
  module QueueAdapters
    class SneakersAdapter
      @monitor = Monitor.new

      class << self
        def enqueue(job)
          @monitor.synchronize do
            JobWrapper.from_queue job.queue_name
            JobWrapper.enqueue ActiveSupport::JSON.encode(job.serialize)
          end
        end

        def enqueue_at(job, timestamp)
          raise NotImplementedError
        end
      end

      class JobWrapper
        include Sneakers::Worker
        from_queue 'active_jobs_default'

        def work(msg)
          job_data = ActiveSupport::JSON.decode(msg)
          Base.execute job_data
          ack!
        end
      end
    end
  end
end