mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
34 lines
764 B
Ruby
34 lines
764 B
Ruby
require 'sneakers'
|
|
require 'thread'
|
|
|
|
module ActiveJob
|
|
module QueueAdapters
|
|
class SneakersAdapter
|
|
@monitor = Monitor.new
|
|
|
|
class << self
|
|
def enqueue(job, *args)
|
|
@monitor.synchronize do
|
|
JobWrapper.from_queue job.queue_name
|
|
JobWrapper.enqueue ActiveSupport::JSON.encode([ job.name, *args ])
|
|
end
|
|
end
|
|
|
|
def enqueue_at(job, timestamp, *args)
|
|
raise NotImplementedError
|
|
end
|
|
end
|
|
|
|
class JobWrapper
|
|
include Sneakers::Worker
|
|
from_queue 'active_jobs_default'
|
|
|
|
def work(msg)
|
|
job_name, *args = ActiveSupport::JSON.decode(msg)
|
|
job_name.constantize.new.execute(*args)
|
|
ack!
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|