lib/mosql/tailer.rb in mosql-0.2.0 vs lib/mosql/tailer.rb in mosql-0.3.0

- old
+ new

@@ -23,14 +23,17 @@ BSON::Timestamp.new(0, 0) end end def write_timestamp(ts) - begin - @table.insert({:service => @service, :timestamp => ts.seconds}) - rescue Sequel::DatabaseError => e - raise unless e.message =~ /duplicate key value violates unique constraint/ - @table.where(:service => @service).update(:timestamp => ts.seconds) + unless @did_insert + begin + @table.insert({:service => @service, :timestamp => ts.seconds}) + rescue Sequel::DatabaseError => e + raise unless MoSQL::SQLAdapter.duplicate_key_error?(e) + end + @did_insert = true end + @table.where(:service => @service).update(:timestamp => ts.seconds) end end end