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

47 lines
1.2 KiB
Ruby
Raw Normal View History

2014-05-19 18:56:08 -04:00
require 'sneakers'
require 'thread'
2014-05-19 18:56:08 -04:00
module ActiveJob
module QueueAdapters
2014-09-21 16:20:23 -04:00
# == Sneakers adapter for Active Job
#
# A high-performance RabbitMQ background processing framework for Ruby.
# Sneakers is being used in production for both I/O and CPU intensive
# workloads, and have achieved the goals of high-performance and
# 0-maintenance, as designed.
#
# Read more about Sneakers {here}[https://github.com/jondot/sneakers].
#
# To use Sneakers set the queue_adapter config to +:sneakers+.
#
# Rails.application.config.active_job.queue_adapter = :sneakers
2014-05-19 18:56:08 -04:00
class SneakersAdapter
2014-05-22 16:38:01 -04:00
@monitor = Monitor.new
2014-05-19 18:56:08 -04:00
class << self
2014-09-21 16:20:23 -04:00
def enqueue(job) #:nodoc:
2014-05-22 16:38:01 -04:00
@monitor.synchronize do
JobWrapper.from_queue job.queue_name
2014-08-25 10:34:50 -04:00
JobWrapper.enqueue ActiveSupport::JSON.encode(job.serialize)
end
2014-05-19 18:56:08 -04:00
end
2014-09-21 16:20:23 -04:00
def enqueue_at(job, timestamp) #:nodoc:
raise NotImplementedError
end
2014-05-19 18:56:08 -04:00
end
class JobWrapper #:nodoc:
2014-05-19 18:56:08 -04:00
include Sneakers::Worker
2014-08-18 03:19:41 -04:00
from_queue 'default'
2014-05-19 18:56:08 -04:00
def work(msg)
2014-08-25 10:34:50 -04:00
job_data = ActiveSupport::JSON.decode(msg)
Base.execute job_data
ack!
2014-05-19 18:56:08 -04:00
end
end
end
end
end