diff options
Diffstat (limited to 'lib/tapicero/couch_changes.rb')
-rw-r--r-- | lib/tapicero/couch_changes.rb | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/tapicero/couch_changes.rb b/lib/tapicero/couch_changes.rb index 376eb11..b45d54a 100644 --- a/lib/tapicero/couch_changes.rb +++ b/lib/tapicero/couch_changes.rb @@ -20,11 +20,20 @@ module Tapicero end end + def deleted(hash = {}, &block) + if block_given? + @deleted = block + else + @deleted && @deleted.call(hash) + end + end + def listen Tapicero.logger.info "listening..." 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 @@ -36,10 +45,9 @@ module Tapicero def callbacks(hash) #changed callback - return if hash["deleted"] # deleted_callback 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 @@ -49,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 + Tapicero.logger.debug "Found sequence: #{@since}" rescue Errno::ENOENT => e Tapicero.logger.warn "No sequence file found. Starting from scratch" end |