diff options
author | Azul <azul@riseup.net> | 2013-11-18 17:20:28 +0100 |
---|---|---|
committer | Azul <azul@riseup.net> | 2013-11-18 17:21:00 +0100 |
commit | bff519f9842e43ad7a5b5e4836d9b73ceeff4681 (patch) | |
tree | 126ccce593bfd44e77a14aacdc4e55126a44316b /lib | |
parent | 38e21726bb9e8f6e0391e50d82e79821fd6c459f (diff) |
fix issues with storing and retrieving the sequence
.to_i makes retrieving the sequence more robust - in particular if the file content was not meaningful.
store_seq should also be called if it was a destroy action.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tapicero/couch_changes.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/tapicero/couch_changes.rb b/lib/tapicero/couch_changes.rb index 35d4b1a..64ae123 100644 --- a/lib/tapicero/couch_changes.rb +++ b/lib/tapicero/couch_changes.rb @@ -33,6 +33,7 @@ module Tapicero Tapicero.logger.debug "Starting at sequence #{since}" db.changes :feed => :continuous, :since => since, :heartbeat => 1000 do |hash| callbacks(hash) + store_seq(hash["seq"]) end end @@ -44,10 +45,9 @@ module Tapicero def callbacks(hash) #changed callback - return deleted(hash) if hash["deleted"] return unless changes = hash["changes"] + return deleted(hash) if hash["deleted"] created(hash) if changes[0]["rev"].start_with?('1-') - store_seq(hash["seq"]) #updated callback end @@ -57,7 +57,8 @@ module Tapicero unless File.writable?(seq_filename) raise StandardError.new("Can't access sequence file") end - @since = File.read(seq_filename) + @since = File.read(seq_filename).to_i + puts @since rescue Errno::ENOENT => e Tapicero.logger.warn "No sequence file found. Starting from scratch" end |