Class: QueueDispatcher::QueueDispatcherProxy
- Inherits:
-
ActiveSupport::ProxyObject
- Object
- ActiveSupport::ProxyObject
- QueueDispatcher::QueueDispatcherProxy
- Defined in:
- lib/queue_dispatcher/message_sending.rb
Instance Method Summary collapse
-
#initialize(target, options = {}) ⇒ QueueDispatcherProxy
constructor
A new instance of QueueDispatcherProxy.
- #method_missing(method, *args) ⇒ Object
Constructor Details
#initialize(target, options = {}) ⇒ QueueDispatcherProxy
Returns a new instance of QueueDispatcherProxy.
3 4 5 6 7 8 9 |
# File 'lib/queue_dispatcher/message_sending.rb', line 3 def initialize(target, = {}) ## Workaround for Rails 4.2: All serialized objects which respond to :id will get typecasted by its id. This ## behaviour doesn't allow to store ActiveRecord objects. We handle this, by encapsulating all objects in ## before storing. @target = TargetContainer.new(target) @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/queue_dispatcher/message_sending.rb', line 11 def method_missing(method, *args) # Find or create the task_queue terminate_immediately = @options.delete(:terminate_immediately) terminate_immediately = terminate_immediately.nil? ? false : terminate_immediately terminate_immediately = @options[:queue].nil? ? true : terminate_immediately task_queue_name = @options.delete(:queue) || "#{@target.payload.to_s}_#{::Time.now.to_f}" task_queue = ::TaskQueue.find_or_create_by_name task_queue_name, terminate_immediately: terminate_immediately # Create Task default_values = {priority: 100} mandatory_values = {target: @target, method_name: method, args: args, state: 'new', task_queue_id: task_queue.id} ::Task.create default_values.merge(@options).merge(mandatory_values) end |