Module: Euston::EventStore::Persistence::Mongodb::MongoConcurrencyDetection::InstanceMethods
- Defined in:
- lib/euston-eventstore/persistence/mongodb/mongo_concurrency_detection.rb
Instance Method Summary collapse
- #detect_mongo_concurrency(opts = {}, &block) ⇒ Object
- #mongo_error_types_for_current_ruby_platform ⇒ Object
Instance Method Details
#detect_mongo_concurrency(opts = {}, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/euston-eventstore/persistence/mongodb/mongo_concurrency_detection.rb', line 15 def detect_mongo_concurrency opts = {}, &block begin yield rescue *mongo_error_types_for_current_ruby_platform => e if e..include? "E11000" opts.fetch(:on_e11000_error, ->(ex) { raise ConcurrencyError }).call e else opts.fetch(:on_other_error, ->(ex) { raise ex }).call e end end end |
#mongo_error_types_for_current_ruby_platform ⇒ Object
9 10 11 12 13 |
# File 'lib/euston-eventstore/persistence/mongodb/mongo_concurrency_detection.rb', line 9 def mongo_error_types_for_current_ruby_platform errors = [ Mongo::OperationFailure ] errors << NativeException if RUBY_PLATFORM.to_s == 'java' errors end |