Class: Atatus::Spies::SuckerPunchSpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/atatus/spies/sucker_punch.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'sucker_punch'

Instance Method Summary collapse

Instance Method Details

#installObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/atatus/spies/sucker_punch.rb', line 27

def install
  ::SuckerPunch::Job::ClassMethods.class_eval do
    alias :__run_perform_without_atatus :__run_perform

    def __run_perform(*args)
      # This method is reached via JobClass#async_perform
      # or JobClass#perform_in.
      name = to_s
      transaction = Atatus.start_transaction(name, TYPE)
      __run_perform_without_atatus(*args)
      transaction.done 'success'
      transaction&.outcome = Transaction::Outcome::SUCCESS
    rescue ::Exception => e
      # Note that SuckerPunch by default doesn't raise the errors from
      # the user-defined JobClass#perform method as it uses an error
      # handler, accessed via `SuckerPunch.exception_handler`.
      Atatus.report(e, handled: false)
      transaction.done 'error'
      transaction&.outcome = Transaction::Outcome::FAILURE
      raise
    ensure
      Atatus.end_transaction
    end
  end
end