couchrest_changes 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Readme.md +7 -0
- data/lib/couchrest/changes/observer.rb +16 -7
- data/lib/couchrest/changes/version.rb +1 -1
- metadata +8 -2
data/Readme.md
CHANGED
@@ -66,3 +66,10 @@ Examples
|
|
66
66
|
------------------------
|
67
67
|
|
68
68
|
See [tapicero](https://github.com/leapcode/tapicero) for a daemon that uses CouchRest::Changes. Historically CouchRest::Changes was extracted from tapicero.
|
69
|
+
|
70
|
+
Known Issues
|
71
|
+
-------------
|
72
|
+
|
73
|
+
* CouchRest will miss the first change in a continuous feed.
|
74
|
+
https://github.com/couchrest/couchrest/pull/104 has a fix.
|
75
|
+
You might want to monkeypatch it.
|
@@ -39,17 +39,21 @@ module CouchRest::Changes
|
|
39
39
|
def listen
|
40
40
|
info "listening..."
|
41
41
|
debug "Starting at sequence #{since}"
|
42
|
+
last = nil
|
42
43
|
result = db.changes feed_options do |hash|
|
44
|
+
last = hash
|
43
45
|
@retry_count = 0
|
44
|
-
callbacks(hash)
|
46
|
+
callbacks(hash) if hash_for_change?(hash)
|
45
47
|
store_seq(hash["seq"])
|
46
48
|
end
|
47
49
|
raise EOFError
|
48
50
|
# appearently MultiJson has issues with the end of the couch stream.
|
49
51
|
# So sometimes we get a MultiJson::LoadError instead...
|
50
52
|
rescue MultiJson::LoadError, EOFError, RestClient::ServerBrokeConnection
|
51
|
-
retry if retry_without_sequence?(result) || retry_later?
|
52
53
|
info "Couch stream ended."
|
54
|
+
debug result.inspect
|
55
|
+
debug last.inspect
|
56
|
+
retry if retry_without_sequence?(result, last) || retry_later?
|
53
57
|
end
|
54
58
|
|
55
59
|
def last_sequence
|
@@ -74,7 +78,7 @@ module CouchRest::Changes
|
|
74
78
|
def callbacks(hash)
|
75
79
|
# let's not track design document changes
|
76
80
|
return if hash['id'].start_with? '_design/'
|
77
|
-
|
81
|
+
changes = hash["changes"]
|
78
82
|
changed(hash)
|
79
83
|
return deleted(hash) if hash["deleted"]
|
80
84
|
return created(hash) if changes[0]["rev"].start_with?('1-')
|
@@ -114,10 +118,11 @@ module CouchRest::Changes
|
|
114
118
|
File.write Config.seq_file, MultiJson.dump(seq)
|
115
119
|
end
|
116
120
|
|
117
|
-
def retry_without_sequence?(result)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
+
def retry_without_sequence?(result, last_hash)
|
122
|
+
if malformated_sequence?(result) || malformated_sequence?(last_hash)
|
123
|
+
@since = nil
|
124
|
+
info "Trying to start from scratch."
|
125
|
+
end
|
121
126
|
end
|
122
127
|
|
123
128
|
def malformated_sequence?(result)
|
@@ -125,6 +130,10 @@ module CouchRest::Changes
|
|
125
130
|
reason && ( reason.include?('since') || reason == 'badarg' )
|
126
131
|
end
|
127
132
|
|
133
|
+
def hash_for_change?(hash)
|
134
|
+
hash["id"] && hash["changes"]
|
135
|
+
end
|
136
|
+
|
128
137
|
def retry_later?
|
129
138
|
return unless rerun?
|
130
139
|
info "Will retry in 15 seconds."
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchrest_changes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: couchrest
|
@@ -154,12 +154,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
154
|
- - ! '>='
|
155
155
|
- !ruby/object:Gem::Version
|
156
156
|
version: '0'
|
157
|
+
segments:
|
158
|
+
- 0
|
159
|
+
hash: -2972848587685415057
|
157
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
161
|
none: false
|
159
162
|
requirements:
|
160
163
|
- - ! '>='
|
161
164
|
- !ruby/object:Gem::Version
|
162
165
|
version: '0'
|
166
|
+
segments:
|
167
|
+
- 0
|
168
|
+
hash: -2972848587685415057
|
163
169
|
requirements: []
|
164
170
|
rubyforge_project:
|
165
171
|
rubygems_version: 1.8.28
|