class Warren::FrameworkAdaptor::RailsAdaptor

The RailsAdaptor provides error handling and application loading for Rails applications

Public Instance Methods

env() click to toggle source

Returns the rails environment

@return [ActiveSupport::StringInquirer] The rails environment

# File lib/warren/framework_adaptor/rails_adaptor.rb, line 109
def env
  Rails.env
end
handle() { || ... } click to toggle source

Checks ensures a database connection has been checked out before yielding to allow message processing. Rescues loss of the database connection and raises {Warren::Exceptions::TemporaryIssue} to send the consumers to sleep until it recovers.

@return [Void]

# File lib/warren/framework_adaptor/rails_adaptor.rb, line 86
def handle
  with_connection do
    yield
  rescue ConnectionMissing => e
    raise Warren::Exceptions::TemporaryIssue, e.message
  end
end
load_application() click to toggle source

Triggers full loading of the rails application and dependencies

@return [Void]

# File lib/warren/framework_adaptor/rails_adaptor.rb, line 123
def load_application
  $stdout.puts 'Loading application...'
  require './config/environment'
  Warren.load_configuration
  $stdout.puts 'Loaded!'
rescue LoadError
  # Need to work out an elegant way to handle non-rails
  # apps
  $stdout.puts 'Could not auto-load application'
end
logger() click to toggle source

Returns the configured logger

@return [Logger,ActiveSupport::Logger,…] The application logger

# File lib/warren/framework_adaptor/rails_adaptor.rb, line 116
def logger
  Rails.logger
end
recovered?() click to toggle source

Checks that the database has recovered to allow message processing

@return [Bool] Returns true if the application has recovered

# File lib/warren/framework_adaptor/rails_adaptor.rb, line 71
def recovered?
  ActiveRecord::Base.connection.reconnect!
  true
rescue StandardError
  false
end
with_connection() { || ... } click to toggle source
# File lib/warren/framework_adaptor/rails_adaptor.rb, line 94
def with_connection
  begin
    ActiveRecord::Base.connection
  rescue StandardError => e
    raise Warren::Exceptions::TemporaryIssue, e.message
  end

  yield
ensure
  ActiveRecord::Base.clear_active_connections!
end