Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/logstash/inputs/couchdb_changes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,29 @@ def register
module SequenceDB
class File
def initialize(file)
@sequence_path = file
@uri = URI.parse(file)
if @uri.scheme == "redis"
@entry = @uri.path.split(File::SEPARATOR)[-1]
@uri.path = @uri.path.split(File::SEPARATOR)[0...-1].join(File::Separator)
@client = Redis.new(url: @uri)
end
end

def read
::File.exists?(@sequence_path) ? ::File.read(@sequence_path).chomp.strip : 0
if @uri.scheme.nil?
::File.exists?(@sequence_path) ? ::File.read(@sequence_path).chomp.strip : 0
elsif @uri.scheme == "redis"
@client.get(@entry)
end
end

def write(sequence = nil)
sequence = 0 if sequence.nil?
::File.write(@sequence_path, sequence.to_s)
if @uri.scheme.nil?
::File.write(@sequence_path, sequence.to_s)
elsif @uri.scheme == "redis"
@client.set(@entry, sequence)
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions logstash-input-couchdb_changes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "stud", '>= 0.0.22'
s.add_runtime_dependency 'logstash-codec-plain'
s.add_runtime_dependency 'json'
s.add_runtime_dependency 'redis'

s.add_development_dependency 'ftw', '~> 0.0.42'
s.add_development_dependency 'logstash-devutils'
Expand Down