1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/lib/active_job/queue_adapters/sneakers_adapter.rb
2014-09-11 00:38:56 +03:00

34 lines
707 B
Ruby

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 'default'
def work(msg)
job_data = ActiveSupport::JSON.decode(msg)
Base.execute job_data
ack!
end
end
end
end
end