Class: JsonApiResource::Connections::CachedCircuitbreakerServerConnection
- Inherits:
-
Multiconnect::Connection::Base
- Object
- Multiconnect::Connection::Base
- JsonApiResource::Connections::CachedCircuitbreakerServerConnection
- Defined in:
- lib/json_api_resource/connections/cached_circuitbreaker_server_connection.rb
Instance Method Summary collapse
- #empty_set_with_errors(e) ⇒ Object
-
#initialize(options) ⇒ CachedCircuitbreakerServerConnection
constructor
A new instance of CachedCircuitbreakerServerConnection.
- #report_error(e) ⇒ Object
- #request(action, *args) ⇒ Object
Constructor Details
#initialize(options) ⇒ CachedCircuitbreakerServerConnection
Returns a new instance of CachedCircuitbreakerServerConnection.
10 11 12 13 14 |
# File 'lib/json_api_resource/connections/cached_circuitbreaker_server_connection.rb', line 10 def initialize() super @caching = .fetch :caching, true @timeout = Time.now end |
Instance Method Details
#empty_set_with_errors(e) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/json_api_resource/connections/cached_circuitbreaker_server_connection.rb', line 45 def empty_set_with_errors( e ) result = JsonApiClient::ResultSet.new result. = {status: 404} result.errors = ActiveModel::Errors.new(result) result.errors.add("RecordNotFound", e.) result end |
#report_error(e) ⇒ Object
16 17 18 19 20 |
# File 'lib/json_api_resource/connections/cached_circuitbreaker_server_connection.rb', line 16 def report_error( e ) unless e.is_a? ServerNotReadyError error_notifier.notify( self, e ) if error_notifier.present? end end |
#request(action, *args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/json_api_resource/connections/cached_circuitbreaker_server_connection.rb', line 22 def request( action, *args ) if ready_for_request? client_args = args.deep_dup result = client_request(action, *client_args) cache_processor.write(result, client, action, *args) if cache? result else raise ServerNotReadyError end rescue JsonApiClient::Errors::NotFound => e empty_set_with_errors e rescue => e @timeout = timeout # propagate the error up to be handled by Connection::Base raise e end |