lib/emittance/resque/dispatcher.rb in emittance-resque-0.2.0 vs lib/emittance/resque/dispatcher.rb in emittance-resque-1.0.0
- old
+ new
@@ -24,40 +24,48 @@
DEFAULT_QUEUE = :default
class << self
include Emittance::Helpers::ConstantHelpers
+ attr_writer :default_queue
+
+ def default_queue
+ @default_queue || DEFAULT_QUEUE
+ end
+
private
def _process_event(event)
registrations = registrations_for(event.class)
serialized_event = serialize_event(event)
registrations.each { |registration| enqueue_job registration, serialized_event }
end
- def _register(_identifier, &_callback)
+ def _register(_identifier, _params = {}, &_callback)
raise InvalidCallbackError, 'Emittance::Resque cannot accept closures as callbacks at this time'
end
- def _register_method_call(identifier, object, method_name)
+ def _register_method_call(identifier, object, method_name, params = {})
validate_method_call object, method_name
- registrations_for(identifier) << new_registration(object, method_name)
+ registrations_for(identifier) << new_registration(object, method_name, params)
end
- def new_registration(object, method_name)
- MethodCallRegistration.new(object.name, method_name)
+ def new_registration(object, method_name, params = {})
+ queue = params[:queue]
+
+ MethodCallRegistration.new(object.name, method_name, queue)
end
def enqueue_job(registration, event)
queue = queue_from_registration(registration)
::Resque.enqueue_to queue, PROCESS_EVENT_JOB, registration.klass_name, registration.method_name, event
end
def queue_from_registration(registration)
- registration.queue || DEFAULT_QUEUE
+ registration.queue || default_queue
end
def serialize_event(event)
Emittance::Resque::EventSerializer.serialize event
end