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.4 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
def initialize
@monitor = Monitor.new
end
2014-05-22 16:38:01 -04:00
def enqueue(job) #:nodoc:
@monitor.synchronize do
JobWrapper.from_queue job.queue_name
JobWrapper.enqueue ActiveSupport::JSON.encode(job.serialize)
2014-05-19 18:56:08 -04:00
end
end
def enqueue_at(job, timestamp) #:nodoc:
raise NotImplementedError, "This queueing backend does not support scheduling jobs. To see what features are supported go to http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html"
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