Class: Warren::FrameworkAdaptor::RailsAdaptor
- Inherits:
-
Object
- Object
- Warren::FrameworkAdaptor::RailsAdaptor
- Defined in:
- lib/warren/framework_adaptor/rails_adaptor.rb
Overview
The RailsAdaptor provides error handling and application loading for Rails applications
Defined Under Namespace
Classes: ConnectionMissing
Instance Method Summary collapse
-
#env ⇒ ActiveSupport::StringInquirer
Returns the rails environment.
-
#handle ⇒ Void
Checks ensures a database connection has been checked out before yielding to allow message processing.
-
#load_application ⇒ Void
Triggers full loading of the rails application and dependencies.
-
#logger ⇒ Logger, ...
Returns the configured logger.
-
#recovered? ⇒ Bool
Checks that the database has recovered to allow message processing.
- #with_connection ⇒ Object
Instance Method Details
#env ⇒ ActiveSupport::StringInquirer
Returns the rails environment
109 110 111 |
# File 'lib/warren/framework_adaptor/rails_adaptor.rb', line 109 def env Rails.env end |
#handle ⇒ Void
Checks ensures a database connection has been checked out before yielding to allow message processing. Rescues loss of the database connection and raises Exceptions::TemporaryIssue to send the consumers to sleep until it recovers.
86 87 88 89 90 91 92 |
# File 'lib/warren/framework_adaptor/rails_adaptor.rb', line 86 def handle with_connection do yield rescue ConnectionMissing => e raise Warren::Exceptions::TemporaryIssue, e. end end |
#load_application ⇒ Void
Triggers full loading of the rails application and dependencies
123 124 125 126 127 128 129 130 131 132 |
# 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 ⇒ Logger, ...
Returns the configured logger
116 117 118 |
# File 'lib/warren/framework_adaptor/rails_adaptor.rb', line 116 def logger Rails.logger end |
#recovered? ⇒ Bool
Checks that the database has recovered to allow message processing
71 72 73 74 75 76 |
# File 'lib/warren/framework_adaptor/rails_adaptor.rb', line 71 def recovered? ActiveRecord::Base.connection.reconnect! true rescue StandardError false end |
#with_connection ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# 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. end yield ensure ActiveRecord::Base.clear_active_connections! end |