Class: QueueDispatcher::QueueDispatcherProxy
- Inherits:
- ActiveSupport::BasicObject
- 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.
5 6 7 8 |
# File 'lib/queue_dispatcher/message_sending.rb', line 5 def initialize(target, = {}) @target = target @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/queue_dispatcher/message_sending.rb', line 10 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.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 |