Module: Communicator::ExceptionHandler

Defined in:
lib/communicator/exception_handler.rb

Class Method Summary collapse

Class Method Details

.lock!Object

Creates the exception notifier lockfile



31
32
33
34
35
# File 'lib/communicator/exception_handler.rb', line 31

def lock!
  File.open(lockfile, "w+") do |f|
    f.puts "Locked at #{Time.now}"
  end
end

.locked?Boolean

Checks whether mailing exceptions is currently locked

Returns:

  • (Boolean)


26
27
28
# File 'lib/communicator/exception_handler.rb', line 26

def locked?
  File.exist?(lockfile)
end

.lockfileObject

Returns the path to the lockfile, either in rails/tmp if present, otherwise in system-wide tmp



17
18
19
20
21
22
23
# File 'lib/communicator/exception_handler.rb', line 17

def lockfile
  if defined?(Rails)
    Rails.root.join('tmp', 'communicator_exception.lock')
  else
    '/tmp/communicator_exception.lock'
  end
end

.publish_and_reraise(err, subsections) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/communicator/exception_handler.rb', line 3

def publish_and_reraise(err, subsections)
  # Notify using capita/exception_notification fork, but only
  # when notifications are not locked
  if respond_to?(:report_exception) and not locked?
    report_exception err, subsections
    lock!
  end
  
  # Always re-raise!
  raise err
end

.unlock!Object

Removes the exception notifier lockfile



38
39
40
# File 'lib/communicator/exception_handler.rb', line 38

def unlock!
  File.unlink(lockfile) if locked?
end