summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-11-29 13:43:32 -0800
committerjessib <jessib@riseup.net>2013-11-29 13:43:32 -0800
commit8104b882032a851604ba6a2a904c7e267523f158 (patch)
treecab4ef7775e7c3e61e22be87d5802ca425dc7b61
parentddda87a96c6c95c1afc163aea3c0d52943ecd41c (diff)
parentc5fea1a1bfaa6690d4d6728feda566e48af452e9 (diff)
Merge pull request #4 from azul/feature/more_robust_sequence_handling
Feature/more robust sequence handling
-rw-r--r--lib/tapicero/couch_changes.rb15
-rw-r--r--lib/tapicero/user_database.rb9
2 files changed, 16 insertions, 8 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
#
diff --git a/lib/tapicero/user_database.rb b/lib/tapicero/user_database.rb
index ec2694a..8f461ef 100644
--- a/lib/tapicero/user_database.rb
+++ b/lib/tapicero/user_database.rb
@@ -10,10 +10,9 @@ module Tapicero
end
def create
- begin
- CouchRest.new(host).create_db(name)
- rescue RestClient::PreconditionFailed # database already existed
- end
+ CouchRest.new(host).create_db(name)
+ Tapicero.logger.debug "database created successfully."
+ rescue RestClient::PreconditionFailed # database already existed
end
def secure(security)
@@ -27,6 +26,8 @@ module Tapicero
def destroy
db = CouchRest.new(host).database(name)
db.delete! if db
+ Tapicero.logger.debug "database deleted successfully."
+ rescue RestClient::ResourceNotFound # no database found
end
protected