summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2013-11-28 07:44:51 +0100
committerAzul <azul@riseup.net>2013-11-28 11:53:38 +0100
commita5b66b15b7f68a1da31dd3ff0466c3be16f031c0 (patch)
tree918919ebf8eb939d31244b01f5bbb5459c89dd1a
parent905307a871d6dfdce6d7120457bf653b8b6234a3 (diff)
make sequence accept all kinds of json
bigcouch uses arrays for sequence: http://mail-archives.apache.org/mod_mbox/couchdb-user/201301.mbox/%3CCABvT1DEGDCJyvEuFsNJZbXi_NJwJna8NHDnQvpr2h532s0V18g@mail.gmail.com%3E So we should not expect them to be integers. Still have to catch the empty file situation in a meaningful way though.
-rw-r--r--lib/tapicero/couch_changes.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/tapicero/couch_changes.rb b/lib/tapicero/couch_changes.rb
index aa21676..fddebec 100644
--- a/lib/tapicero/couch_changes.rb
+++ b/lib/tapicero/couch_changes.rb
@@ -31,10 +31,12 @@ module Tapicero
def listen
Tapicero.logger.info "listening..."
Tapicero.logger.debug "Starting at sequence #{since}"
- db.changes :feed => :continuous, :since => since, :heartbeat => 1000 do |hash|
+ result = db.changes :feed => :continuous, :since => since, :heartbeat => 1000 do |hash|
callbacks(hash)
store_seq(hash["seq"])
end
+ Tapicero.logger.info "couch stream ended unexpectedly."
+ Tapicero.logger.debug result.inspect
end
protected
@@ -59,14 +61,19 @@ module Tapicero
unless File.writable?(seq_filename)
raise StandardError.new("Can't access sequence file")
end
- @since = File.read(seq_filename).to_i
- Tapicero.logger.debug "Found sequence: #{@since}"
+ @since = File.read(seq_filename)
+ if @since == ''
+ @since = nil
+ Tapicero.logger.debug "Found no sequence in the file."
+ else
+ Tapicero.logger.debug "Found sequence: #{@since}"
+ end
rescue Errno::ENOENT => e
Tapicero.logger.warn "No sequence file found. Starting from scratch"
end
def store_seq(seq)
- File.write(@seq_filename, seq)
+ File.write(@seq_filename, seq.to_json)
end
#