euston-eventstore 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'euston-eventstore'
3
- s.version = '1.2.0'
4
- s.date = '2011-10-12'
3
+ s.version = '1.2.1'
4
+ s.date = '2011-10-13'
5
5
  s.platform = RUBY_PLATFORM.to_s == 'java' ? 'java' : Gem::Platform::RUBY
6
6
  s.authors = ['Lee Henson', 'Guy Boertje']
7
7
  s.email = ['lee.m.henson@gmail.com', 'guyboertje@gmail.com']
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  lib/euston-eventstore/persistence/mongodb/mongo_command_message.rb
28
28
  lib/euston-eventstore/persistence/mongodb/mongo_commit.rb
29
29
  lib/euston-eventstore/persistence/mongodb/mongo_commit_id.rb
30
+ lib/euston-eventstore/persistence/mongodb/mongo_concurrency_detection.rb
30
31
  lib/euston-eventstore/persistence/mongodb/mongo_config.rb
31
32
  lib/euston-eventstore/persistence/mongodb/mongo_event_message.rb
32
33
  lib/euston-eventstore/persistence/mongodb/mongo_persistence_engine.rb
@@ -17,6 +17,7 @@ require 'euston-eventstore/dispatcher/synchronous_dispatcher'
17
17
  require 'euston-eventstore/persistence/stream_head'
18
18
  require 'euston-eventstore/persistence/mongodb/mongo_commit'
19
19
  require 'euston-eventstore/persistence/mongodb/mongo_commit_id'
20
+ require 'euston-eventstore/persistence/mongodb/mongo_concurrency_detection'
20
21
  require 'euston-eventstore/persistence/mongodb/mongo_config'
21
22
  require 'euston-eventstore/persistence/mongodb/mongo_command_message'
22
23
  require 'euston-eventstore/persistence/mongodb/mongo_event_message'
@@ -0,0 +1,31 @@
1
+ module Euston
2
+ module EventStore
3
+ module Persistence
4
+ module Mongodb
5
+ module MongoConcurrencyDetection
6
+ extend ActiveSupport::Concern
7
+
8
+ module InstanceMethods
9
+ def mongo_error_types_for_current_ruby_platform
10
+ errors = [ Mongo::OperationFailure ]
11
+ errors << NativeException if RUBY_PLATFORM.to_s == 'java'
12
+ errors
13
+ end
14
+
15
+ def detect_mongo_concurrency opts = {}, &block
16
+ begin
17
+ yield
18
+ rescue *mongo_error_types_for_current_ruby_platform => e
19
+ if e.message.include? "E11000"
20
+ opts.fetch(:on_e11000_error, ->(ex) { raise ConcurrencyError }).call e
21
+ else
22
+ opts.fetch(:on_other_error, ->(ex) { raise ex }).call e
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -3,6 +3,8 @@ module Euston
3
3
  module Persistence
4
4
  module Mongodb
5
5
  class MongoPersistenceEngine
6
+ include MongoConcurrencyDetection
7
+
6
8
  def initialize(store)
7
9
  @store = store
8
10
 
@@ -42,18 +44,18 @@ module Euston
42
44
  try_mongo do
43
45
  commit = attempt.to_mongo_commit
44
46
 
45
- begin
46
- persisted_commits.insert commit
47
-
48
- update_stream_head_async attempt.stream_id, attempt.stream_revision, attempt.events.length
49
- rescue Mongo::OperationFailure, NativeException => e
50
- raise(Euston::EventStore::StorageError, e.message, e.backtrace) unless e.message.include? CONCURRENCY_EXCEPTION
51
-
47
+ on_e11000_error = ->(e) do
52
48
  committed = persisted_commits.find_one(attempt.to_id_query)
53
-
54
49
  raise Euston::EventStore::DuplicateCommitError if !committed.nil? && committed['commit_id'] == attempt.commit_id
55
50
  raise Euston::EventStore::ConcurrencyError
56
51
  end
52
+
53
+ on_other_error = ->(e) { raise EventStore::StorageError, e.message, e.backtrace }
54
+
55
+ detect_mongo_concurrency :on_e11000_error => on_e11000_error, :on_other_error => on_other_error do
56
+ persisted_commits.insert commit
57
+ update_stream_head_async attempt.stream_id, attempt.stream_revision, attempt.events.length
58
+ end
57
59
  end
58
60
  end
59
61
 
@@ -1,5 +1,5 @@
1
1
  module Euston
2
2
  module EventStore
3
- VERSION = "1.2.0"
3
+ VERSION = "1.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: euston-eventstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-12 00:00:00.000000000 Z
13
+ date: 2011-10-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &81168440 !ruby/object:Gem::Requirement
17
+ requirement: &81855570 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.9
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *81168440
25
+ version_requirements: *81855570
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: euston
28
- requirement: &80665360 !ruby/object:Gem::Requirement
28
+ requirement: &81850100 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *80665360
36
+ version_requirements: *81850100
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: hash-keys
39
- requirement: &80664300 !ruby/object:Gem::Requirement
39
+ requirement: &81848150 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.0.0
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *80664300
47
+ version_requirements: *81848150
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bson
50
- requirement: &80662450 !ruby/object:Gem::Requirement
50
+ requirement: &81844750 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 1.4.0
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *80662450
58
+ version_requirements: *81844750
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: bson_ext
61
- requirement: &80660670 !ruby/object:Gem::Requirement
61
+ requirement: &81844130 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.4.0
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *80660670
69
+ version_requirements: *81844130
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: json
72
- requirement: &80659140 !ruby/object:Gem::Requirement
72
+ requirement: &81843780 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 1.5.0
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *80659140
80
+ version_requirements: *81843780
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: mongo
83
- requirement: &80656520 !ruby/object:Gem::Requirement
83
+ requirement: &81843240 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: 1.4.0
89
89
  type: :runtime
90
90
  prerelease: false
91
- version_requirements: *80656520
91
+ version_requirements: *81843240
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: uuid
94
- requirement: &80655690 !ruby/object:Gem::Requirement
94
+ requirement: &81842810 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ~>
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: 2.3.0
100
100
  type: :runtime
101
101
  prerelease: false
102
- version_requirements: *80655690
102
+ version_requirements: *81842810
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: awesome_print
105
- requirement: &80654900 !ruby/object:Gem::Requirement
105
+ requirement: &81842360 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ~>
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: 0.4.0
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *80654900
113
+ version_requirements: *81842360
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: fuubar
116
- requirement: &80651070 !ruby/object:Gem::Requirement
116
+ requirement: &81841290 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ~>
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: 0.0.0
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *80651070
124
+ version_requirements: *81841290
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rake
127
- requirement: &80650260 !ruby/object:Gem::Requirement
127
+ requirement: &81840650 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ~>
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: 0.9.2
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *80650260
135
+ version_requirements: *81840650
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: rspec
138
- requirement: &80648850 !ruby/object:Gem::Requirement
138
+ requirement: &81838940 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ~>
@@ -143,7 +143,7 @@ dependencies:
143
143
  version: 2.6.0
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *80648850
146
+ version_requirements: *81838940
147
147
  description: Ruby port for Jonathan Oliver's EventStore. See https://github.com/joliver/EventStore
148
148
  for details.
149
149
  email:
@@ -170,6 +170,7 @@ files:
170
170
  - lib/euston-eventstore/persistence/mongodb/mongo_command_message.rb
171
171
  - lib/euston-eventstore/persistence/mongodb/mongo_commit.rb
172
172
  - lib/euston-eventstore/persistence/mongodb/mongo_commit_id.rb
173
+ - lib/euston-eventstore/persistence/mongodb/mongo_concurrency_detection.rb
173
174
  - lib/euston-eventstore/persistence/mongodb/mongo_config.rb
174
175
  - lib/euston-eventstore/persistence/mongodb/mongo_event_message.rb
175
176
  - lib/euston-eventstore/persistence/mongodb/mongo_persistence_engine.rb