From bff519f9842e43ad7a5b5e4836d9b73ceeff4681 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 18 Nov 2013 17:20:28 +0100 Subject: 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. --- lib/tapicero/couch_changes.rb | 7 ++++--- 1 file 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 -- cgit v1.2.3