Created
July 24, 2013 19:52
-
-
Save orangewolf/6073928 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| index c6a1704..e98119d 100644 | |
| --- a/lib/couchchanges.rb | |
| +++ b/lib/couchchanges.rb | |
| @@ -6,7 +6,7 @@ class CouchChanges | |
| def initialize options={} | |
| @options = options.dup | |
| @uri = URI.parse(@options.delete(:url) + "/_changes") | |
| - @last_seq = 0 | |
| + @last_seq = options[:since] || 0 | |
| end | |
| def change &block | |
| @@ -47,21 +47,25 @@ class CouchChanges | |
| if @uri.user | |
| options[:head] = {'authorization' => [@uri.user, @uri.password]} | |
| end | |
| - | |
| + | |
| EM::HttpRequest.new(@uri.to_s).get(options) | |
| end | |
| def handle line | |
| return if line.chomp.empty? | |
| - hash = JSON.parse(line) | |
| - if hash["last_seq"] | |
| - disconnected | |
| - else | |
| - hash["rev"] = hash.delete("changes")[0]["rev"] | |
| - @last_seq = hash["seq"] | |
| + begin | |
| + hash = JSON.parse(line) | |
| + if hash["last_seq"] | |
| + disconnected | |
| + else | |
| + hash["rev"] = hash.delete("changes")[0]["rev"] | |
| + @last_seq = hash["seq"] | |
| - callbacks hash | |
| + callbacks hash | |
| + end | |
| + rescue Exception => e | |
| + Airbrake.notify(e, :session => {:line => line.inspect, :hash => hash.inspect}) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment