Module: TorqueBox::Messaging::Backgroundable::ClassMethods

Defined in:
lib/torquebox/messaging/backgroundable.rb

Instance Method Summary collapse

Instance Method Details

#__enable_backgroundable_newrelic_tracing(method) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/torquebox/messaging/backgroundable.rb', line 95

def __enable_backgroundable_newrelic_tracing(method)
  method = method.to_s
  if Backgroundable.newrelic_available?
    TorqueBox::Messaging::Backgroundable::MUTEX.synchronize do
      @__enabled_bg_tracing_methods ||= {}
      if !@__enabled_bg_tracing_methods[method]
        include(NewRelic::Agent::Instrumentation::ControllerInstrumentation) unless
          include?(NewRelic::Agent::Instrumentation::ControllerInstrumentation)
        begin
          add_transaction_tracer(method, :name => method.sub("__sync_", ""), :category => :task)
        rescue Exception => e
          TorqueBox::Logger.new( Backgroundable ).error "Error loading New Relic for backgrounded method #{method.sub("__sync_", "")}: #{e}"
        end
        @__enabled_bg_tracing_methods[method] = true
      end
    end
  end
end

#always_background(*methods) ⇒ Object

Marks methods to always be backgrounded. Takes one or more method symbols, and an optional options hash as the final argument. The options allow you to set publish options for each call. see TorqueBox::Messaging::Destination#publish



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/torquebox/messaging/backgroundable.rb', line 59

def always_background(*methods)
  options = methods.last.is_a?(Hash) ? methods.pop : {}
  @__backgroundable_methods ||= {}

  methods.each do |method|
    method = method.to_s
    if !@__backgroundable_methods[method]
      @__backgroundable_methods[method] ||= { }
      @__backgroundable_methods[method][:options] = options
      if Util.singleton_methods_include?(self, method) ||
          Util.instance_methods_include?(self, method)
        __enable_backgrounding(method)
      end
    end
  end
end

#background(options = { }) ⇒ Future

Allows you to background any method that has not been marked as a backgrounded method via #always_background.

Parameters:

Returns:



81
82
83
# File 'lib/torquebox/messaging/backgroundable.rb', line 81

def background(options = { })
  BackgroundProxy.new(self, options)
end

#method_added(method) ⇒ Object



85
86
87
88
# File 'lib/torquebox/messaging/backgroundable.rb', line 85

def method_added(method)
  super
  __method_added(method)
end

#singleton_method_added(method) ⇒ Object



90
91
92
93
# File 'lib/torquebox/messaging/backgroundable.rb', line 90

def singleton_method_added(method)
  super
  __method_added(method)
end