Class: Isono::Rack::Sequel
- Includes:
- Logger
- Defined in:
- lib/isono/rack/sequel.rb
Overview
Middleware for Sequel transaction.
Instance Attribute Summary
Attributes inherited from Decorator
Instance Method Summary collapse
- #call(req, res) ⇒ Object
-
#initialize(app, retry_count = 10) ⇒ Sequel
constructor
A new instance of Sequel.
Methods included from Logger
Constructor Details
#initialize(app, retry_count = 10) ⇒ Sequel
Returns a new instance of Sequel.
11 12 13 14 |
# File 'lib/isono/rack/sequel.rb', line 11 def initialize(app, retry_count=10) @app = app @retry_count = retry_count end |
Instance Method Details
#call(req, res) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/isono/rack/sequel.rb', line 16 def call(req, res) retry_count=0 begin ::Sequel::DATABASES.first.transaction do @app.call(req, res) res.response(ret) unless res.responded? end rescue ::Sequel::DatabaseError, ::Sequel::DatabaseConnectionError => e retry_count += 1 if retry_count < @retry_count logger.error("Database Error: #{e.} retrying #{retry_count}/#{@retry_count}") retry end res.response(e) unless res.responded? raise e end end |