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
117 118 119 |
# File 'lib/warren/framework_adaptor/rails_adaptor.rb', line 117 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
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/warren/framework_adaptor/rails_adaptor.rb', line 131 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
124 125 126 |
# File 'lib/warren/framework_adaptor/rails_adaptor.rb', line 124 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 105 106 107 108 109 110 111 112 |
# 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 # Although Rails 7.2 recommends using `ActiveRecord::Base.connection_handler.clear_active_connections!` # to clear all active connections (especially in applications with multiple databases), # Y25-234 investigated the performance and applicability of this versus # `ActiveRecord::Base.connection_pool.release_connection`. # # Since Unified Warehouse (the primary Warren consumer) does not use multiple databases, # `release_connection` was found to be more targeted and performant. # Using `clear_active_connections!` would be redundant and potentially less efficient in this context. ActiveRecord::Base.connection_pool.release_connection end |