class QueueDispatcher::QueueDispatcherProxy

Public Class Methods

new(target, options = {}) click to toggle source
# File lib/queue_dispatcher/message_sending.rb, line 3
def initialize(target, options = {})
  ## 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 = options
end

Public Instance Methods

method_missing(method, *args) click to toggle source
# 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