tengine_core 0.5.36 → 0.5.37
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/tengine/core/event.rb +4 -3
- data/lib/tengine/core/kernel.rb +25 -11
- data/lib/tengine/core/mongoid_fix.rb +11 -9
- data/spec/tengine/core/mutex_spec.rb +3 -3
- data/tengine_core.gemspec +1 -1
- metadata +39 -40
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.37
|
data/lib/tengine/core/event.rb
CHANGED
@@ -70,10 +70,11 @@ class Tengine::Core::Event
|
|
70
70
|
# @yieldparam [Tengine::Core::Event] event The event in question.
|
71
71
|
# @yieldreturn [Boolean] Return false, and it will just break the execution. Otherwise, it tries to update the event.
|
72
72
|
# @param [Hash] condition Criteria to find a document.
|
73
|
-
# @param [Numeric] retry_max (
|
73
|
+
# @param [Numeric] retry_max (60) Maximum number of retry attempts to save the event.
|
74
|
+
# @param [Numeric] wtimeout (10240) Write timeout, ignored for earlier mongodb.
|
74
75
|
# @return [Tengine::Core::Event] The event in question if update succeeded, false if retry_max reached, or nil if the block exited with false.
|
75
76
|
# @raise [Mongo::OperationFailure] Any exceptions that happened inside will be propagated outside.
|
76
|
-
def self.find_or_create_then_update_with_block condition, retry_max =
|
77
|
+
def self.find_or_create_then_update_with_block condition, retry_max = 60, wtimeout = 10240
|
77
78
|
# * とある条件を満たすイベントがあれば、それを上書きしたい。
|
78
79
|
# * なければ、新規作成したい。
|
79
80
|
# * でもアトミックにやりたい。
|
@@ -86,7 +87,7 @@ class Tengine::Core::Event
|
|
86
87
|
results = nil
|
87
88
|
|
88
89
|
case collection.driver.db.connection when Mongo::ReplSetConnection then
|
89
|
-
safemode = { :w => "majority", :wtimeout =>
|
90
|
+
safemode = { :w => "majority", :wtimeout => wtimeout, } # mongodb 2.0+, 参加しているレプリカセットの多数派に書き込んだ時点でOK扱い
|
90
91
|
else
|
91
92
|
safemode = true
|
92
93
|
end
|
data/lib/tengine/core/kernel.rb
CHANGED
@@ -181,7 +181,15 @@ class Tengine::Core::Kernel
|
|
181
181
|
unless event
|
182
182
|
# Model.exists?だと上手くいかない時があるのでModel.whereを使っています
|
183
183
|
# fire_failed_event(raw_event) if Tengine::Core::Event.exists?(confitions: { key: raw_event.key, sender_name: raw_event.sender_name })
|
184
|
-
|
184
|
+
|
185
|
+
begin
|
186
|
+
n = Tengine::Core::Event.where(:key => raw_event.key, :sender_name => raw_event.sender_name).count
|
187
|
+
rescue Mongo::ConnectionFailure, Mongo::OperationTimeout, Mongo::OperationFailure => e
|
188
|
+
Tengine.logger.error("giving up processing an event due to #{e} (#{e.class.name})")
|
189
|
+
n = 0
|
190
|
+
end
|
191
|
+
|
192
|
+
if n > 0
|
185
193
|
fire_failed_event(raw_event)
|
186
194
|
headers.ack
|
187
195
|
else
|
@@ -192,18 +200,24 @@ class Tengine::Core::Kernel
|
|
192
200
|
end
|
193
201
|
event.kernel = self
|
194
202
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
203
|
+
begin
|
204
|
+
ack_policy = ack_policy_for(event)
|
205
|
+
safety_processing_headers(headers, event, ack_policy) do
|
206
|
+
ack if ack_policy == :at_first
|
207
|
+
handlers = find_handlers(event)
|
208
|
+
safty_handlers(handlers) do
|
209
|
+
delegate(event, handlers)
|
210
|
+
ack if all_submitted?
|
211
|
+
end
|
212
|
+
headers.reject(:requeue => true) unless ack?
|
202
213
|
end
|
203
|
-
|
214
|
+
close_if_shutting_down
|
215
|
+
true
|
216
|
+
rescue Mongo::ConnectionFailure, Mongo::OperationTimeout, Mongo::OperationFailure => e
|
217
|
+
Tengine.logger.error("giving up processing an event due to #{e} (#{e.class.name})")
|
218
|
+
Tengine.logger.info("requeue an event #{raw_event.inspect}")
|
219
|
+
headers.reject(:requeue => true)
|
204
220
|
end
|
205
|
-
close_if_shutting_down
|
206
|
-
true
|
207
221
|
end
|
208
222
|
end
|
209
223
|
|
@@ -15,22 +15,24 @@ if Mongoid::VERSION < "3.0.0"
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
+
end
|
18
19
|
|
20
|
+
module Mongoid::Collections::Retry
|
19
21
|
# https://github.com/mongoid/mongoid/pull/1739
|
22
|
+
# Mongoid 2.3.x needs additional fix
|
20
23
|
def retry_on_connection_failure
|
21
24
|
retries = 0
|
22
25
|
begin
|
23
26
|
yield
|
24
|
-
rescue Mongo::ConnectionFailure, Mongo::OperationTimeout => ex
|
25
|
-
|
27
|
+
rescue Mongo::ConnectionFailure, Mongo::OperationTimeout, Mongo::OperationFailure => ex
|
28
|
+
raise unless ex.class == Mongo::OperationFailure and ex.message !~ /not master/
|
29
|
+
|
30
|
+
retries += 1
|
31
|
+
raise if retries > Mongoid.max_retries_on_connection_failure
|
32
|
+
|
33
|
+
Kernel.sleep(0.5)
|
34
|
+
log_retry retries
|
26
35
|
retry
|
27
|
-
rescue Mongo::OperationFailure => ex
|
28
|
-
if ex.message =~ /not master/
|
29
|
-
retries = increase_retry_attempts(retries, ex)
|
30
|
-
retry
|
31
|
-
else
|
32
|
-
raise ex
|
33
|
-
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -80,7 +80,7 @@ describe Tengine::Core::Mutex do
|
|
80
80
|
t1 = Time.now
|
81
81
|
block_called.should be_true
|
82
82
|
m.reload.waiters.should be_empty
|
83
|
-
(t1 - t0).should be_within(0
|
83
|
+
(t1 - t0).should be_within(1.0).of(0.3 + m.ttl)
|
84
84
|
end
|
85
85
|
|
86
86
|
it "synchronizes #3: with another locker, which is not expiring" do
|
@@ -106,7 +106,7 @@ describe Tengine::Core::Mutex do
|
|
106
106
|
t1 = Time.now
|
107
107
|
block_called.should be_true
|
108
108
|
m.reload.waiters.should be_empty
|
109
|
-
(t1 - t0).should be_within(0
|
109
|
+
(t1 - t0).should be_within(1.0).of(5 + m.ttl)
|
110
110
|
end
|
111
111
|
|
112
112
|
it "synchronizes #4: multi-threaded situation" do
|
@@ -178,7 +178,7 @@ describe Tengine::Core::Mutex do
|
|
178
178
|
end
|
179
179
|
|
180
180
|
t1.should_not be_nil
|
181
|
-
(t1 - t0).should be_within(0
|
181
|
+
(t1 - t0).should be_within(1.0).of(10 * subject.mutex.ttl)
|
182
182
|
end
|
183
183
|
end
|
184
184
|
end
|
data/tengine_core.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "tengine_core"
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.37"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["taigou", "totty", "g-morita", "shyouhei", "akm", "hiroshinakao"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tengine_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.37
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,7 +18,7 @@ date: 2012-02-22 00:00:00.000000000Z
|
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activesupport
|
21
|
-
requirement: &
|
21
|
+
requirement: &70303062943180 !ruby/object:Gem::Requirement
|
22
22
|
none: false
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
@@ -26,10 +26,10 @@ dependencies:
|
|
26
26
|
version: 3.1.0
|
27
27
|
type: :runtime
|
28
28
|
prerelease: false
|
29
|
-
version_requirements: *
|
29
|
+
version_requirements: *70303062943180
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: activemodel
|
32
|
-
requirement: &
|
32
|
+
requirement: &70303062942700 !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
@@ -37,10 +37,10 @@ dependencies:
|
|
37
37
|
version: 3.1.0
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
|
-
version_requirements: *
|
40
|
+
version_requirements: *70303062942700
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: selectable_attr
|
43
|
-
requirement: &
|
43
|
+
requirement: &70303062942220 !ruby/object:Gem::Requirement
|
44
44
|
none: false
|
45
45
|
requirements:
|
46
46
|
- - ~>
|
@@ -48,10 +48,10 @@ dependencies:
|
|
48
48
|
version: 0.3.15
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
|
-
version_requirements: *
|
51
|
+
version_requirements: *70303062942220
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
53
|
name: bson
|
54
|
-
requirement: &
|
54
|
+
requirement: &70303062941740 !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
56
56
|
requirements:
|
57
57
|
- - ~>
|
@@ -59,10 +59,10 @@ dependencies:
|
|
59
59
|
version: 1.5.2
|
60
60
|
type: :runtime
|
61
61
|
prerelease: false
|
62
|
-
version_requirements: *
|
62
|
+
version_requirements: *70303062941740
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
name: bson_ext
|
65
|
-
requirement: &
|
65
|
+
requirement: &70303062941260 !ruby/object:Gem::Requirement
|
66
66
|
none: false
|
67
67
|
requirements:
|
68
68
|
- - ~>
|
@@ -70,10 +70,10 @@ dependencies:
|
|
70
70
|
version: 1.5.2
|
71
71
|
type: :runtime
|
72
72
|
prerelease: false
|
73
|
-
version_requirements: *
|
73
|
+
version_requirements: *70303062941260
|
74
74
|
- !ruby/object:Gem::Dependency
|
75
75
|
name: mongo
|
76
|
-
requirement: &
|
76
|
+
requirement: &70303062940780 !ruby/object:Gem::Requirement
|
77
77
|
none: false
|
78
78
|
requirements:
|
79
79
|
- - ~>
|
@@ -81,10 +81,10 @@ dependencies:
|
|
81
81
|
version: 1.5.2
|
82
82
|
type: :runtime
|
83
83
|
prerelease: false
|
84
|
-
version_requirements: *
|
84
|
+
version_requirements: *70303062940780
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: mongoid
|
87
|
-
requirement: &
|
87
|
+
requirement: &70303062940300 !ruby/object:Gem::Requirement
|
88
88
|
none: false
|
89
89
|
requirements:
|
90
90
|
- - ~>
|
@@ -92,10 +92,10 @@ dependencies:
|
|
92
92
|
version: 2.3.3
|
93
93
|
type: :runtime
|
94
94
|
prerelease: false
|
95
|
-
version_requirements: *
|
95
|
+
version_requirements: *70303062940300
|
96
96
|
- !ruby/object:Gem::Dependency
|
97
97
|
name: tengine_support
|
98
|
-
requirement: &
|
98
|
+
requirement: &70303062939820 !ruby/object:Gem::Requirement
|
99
99
|
none: false
|
100
100
|
requirements:
|
101
101
|
- - ~>
|
@@ -103,10 +103,10 @@ dependencies:
|
|
103
103
|
version: 0.3.12
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
|
-
version_requirements: *
|
106
|
+
version_requirements: *70303062939820
|
107
107
|
- !ruby/object:Gem::Dependency
|
108
108
|
name: tengine_event
|
109
|
-
requirement: &
|
109
|
+
requirement: &70303062939340 !ruby/object:Gem::Requirement
|
110
110
|
none: false
|
111
111
|
requirements:
|
112
112
|
- - ~>
|
@@ -114,10 +114,10 @@ dependencies:
|
|
114
114
|
version: 0.4.0
|
115
115
|
type: :runtime
|
116
116
|
prerelease: false
|
117
|
-
version_requirements: *
|
117
|
+
version_requirements: *70303062939340
|
118
118
|
- !ruby/object:Gem::Dependency
|
119
119
|
name: daemons
|
120
|
-
requirement: &
|
120
|
+
requirement: &70303062955240 !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
123
123
|
- - ~>
|
@@ -125,10 +125,10 @@ dependencies:
|
|
125
125
|
version: 1.1.4
|
126
126
|
type: :runtime
|
127
127
|
prerelease: false
|
128
|
-
version_requirements: *
|
128
|
+
version_requirements: *70303062955240
|
129
129
|
- !ruby/object:Gem::Dependency
|
130
130
|
name: rspec
|
131
|
-
requirement: &
|
131
|
+
requirement: &70303062954760 !ruby/object:Gem::Requirement
|
132
132
|
none: false
|
133
133
|
requirements:
|
134
134
|
- - ~>
|
@@ -136,10 +136,10 @@ dependencies:
|
|
136
136
|
version: 2.6.0
|
137
137
|
type: :development
|
138
138
|
prerelease: false
|
139
|
-
version_requirements: *
|
139
|
+
version_requirements: *70303062954760
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
141
|
name: factory_girl
|
142
|
-
requirement: &
|
142
|
+
requirement: &70303062954280 !ruby/object:Gem::Requirement
|
143
143
|
none: false
|
144
144
|
requirements:
|
145
145
|
- - ~>
|
@@ -147,10 +147,10 @@ dependencies:
|
|
147
147
|
version: 2.1.2
|
148
148
|
type: :development
|
149
149
|
prerelease: false
|
150
|
-
version_requirements: *
|
150
|
+
version_requirements: *70303062954280
|
151
151
|
- !ruby/object:Gem::Dependency
|
152
152
|
name: yard
|
153
|
-
requirement: &
|
153
|
+
requirement: &70303062953800 !ruby/object:Gem::Requirement
|
154
154
|
none: false
|
155
155
|
requirements:
|
156
156
|
- - ~>
|
@@ -158,10 +158,10 @@ dependencies:
|
|
158
158
|
version: 0.7.2
|
159
159
|
type: :development
|
160
160
|
prerelease: false
|
161
|
-
version_requirements: *
|
161
|
+
version_requirements: *70303062953800
|
162
162
|
- !ruby/object:Gem::Dependency
|
163
163
|
name: bundler
|
164
|
-
requirement: &
|
164
|
+
requirement: &70303062953320 !ruby/object:Gem::Requirement
|
165
165
|
none: false
|
166
166
|
requirements:
|
167
167
|
- - ~>
|
@@ -169,10 +169,10 @@ dependencies:
|
|
169
169
|
version: 1.0.18
|
170
170
|
type: :development
|
171
171
|
prerelease: false
|
172
|
-
version_requirements: *
|
172
|
+
version_requirements: *70303062953320
|
173
173
|
- !ruby/object:Gem::Dependency
|
174
174
|
name: jeweler
|
175
|
-
requirement: &
|
175
|
+
requirement: &70303062952840 !ruby/object:Gem::Requirement
|
176
176
|
none: false
|
177
177
|
requirements:
|
178
178
|
- - ~>
|
@@ -180,10 +180,10 @@ dependencies:
|
|
180
180
|
version: 1.6.4
|
181
181
|
type: :development
|
182
182
|
prerelease: false
|
183
|
-
version_requirements: *
|
183
|
+
version_requirements: *70303062952840
|
184
184
|
- !ruby/object:Gem::Dependency
|
185
185
|
name: simplecov
|
186
|
-
requirement: &
|
186
|
+
requirement: &70303062952360 !ruby/object:Gem::Requirement
|
187
187
|
none: false
|
188
188
|
requirements:
|
189
189
|
- - ~>
|
@@ -191,10 +191,10 @@ dependencies:
|
|
191
191
|
version: 0.5.3
|
192
192
|
type: :development
|
193
193
|
prerelease: false
|
194
|
-
version_requirements: *
|
194
|
+
version_requirements: *70303062952360
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: ZenTest
|
197
|
-
requirement: &
|
197
|
+
requirement: &70303062951880 !ruby/object:Gem::Requirement
|
198
198
|
none: false
|
199
199
|
requirements:
|
200
200
|
- - ~>
|
@@ -202,10 +202,10 @@ dependencies:
|
|
202
202
|
version: 4.6.2
|
203
203
|
type: :development
|
204
204
|
prerelease: false
|
205
|
-
version_requirements: *
|
205
|
+
version_requirements: *70303062951880
|
206
206
|
- !ruby/object:Gem::Dependency
|
207
207
|
name: rdiscount
|
208
|
-
requirement: &
|
208
|
+
requirement: &70303062951400 !ruby/object:Gem::Requirement
|
209
209
|
none: false
|
210
210
|
requirements:
|
211
211
|
- - ! '>='
|
@@ -213,10 +213,10 @@ dependencies:
|
|
213
213
|
version: '0'
|
214
214
|
type: :development
|
215
215
|
prerelease: false
|
216
|
-
version_requirements: *
|
216
|
+
version_requirements: *70303062951400
|
217
217
|
- !ruby/object:Gem::Dependency
|
218
218
|
name: kramdown
|
219
|
-
requirement: &
|
219
|
+
requirement: &70303062950920 !ruby/object:Gem::Requirement
|
220
220
|
none: false
|
221
221
|
requirements:
|
222
222
|
- - ! '>='
|
@@ -224,7 +224,7 @@ dependencies:
|
|
224
224
|
version: '0'
|
225
225
|
type: :development
|
226
226
|
prerelease: false
|
227
|
-
version_requirements: *
|
227
|
+
version_requirements: *70303062950920
|
228
228
|
description: tengine_core is a framework/engine to support distributed processing
|
229
229
|
email: tengine@nautilus-technologies.com
|
230
230
|
executables:
|
@@ -418,4 +418,3 @@ signing_key:
|
|
418
418
|
specification_version: 3
|
419
419
|
summary: tengine_core is a framework/engine to support distributed processing
|
420
420
|
test_files: []
|
421
|
-
has_rdoc:
|