Skip to content

Commit

Permalink
Implement plugin stop behavior
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
andrewvc authored and jordansissel committed Sep 22, 2015
1 parent 2e35b63 commit cb332d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/logstash/inputs/sqlite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require "logstash/inputs/base"
require "logstash/namespace"
require "socket"
require "stud/interval"
require "concurrent"


# Read rows from an sqlite database.
Expand Down Expand Up @@ -146,7 +148,7 @@ def run(queue)

begin
@logger.debug("Tailing sqlite db", :path => @path)
loop do
until stop?
count = 0
@table_data.each do |k, table|
table_name = table[:name]
Expand Down Expand Up @@ -174,7 +176,8 @@ def run(queue)
# sleep a bit
@logger.debug("No new rows. Sleeping.", :time => sleeptime)
sleeptime = [sleeptime * 2, sleep_max].min
sleep(sleeptime)

Stud.stoppable_sleep(sleeptime) { stop? }
else
sleeptime = sleep_min
end
Expand Down
1 change: 1 addition & 0 deletions logstash-input-sqlite.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'jdbc-sqlite3'

s.add_development_dependency 'logstash-devutils'
s.add_development_dependency 'logstash-codec-plain'
end

10 changes: 10 additions & 0 deletions spec/inputs/sqlite_spec.rb
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# encoding: utf-8
require "logstash/devutils/rspec/spec_helper"
require "logstash/inputs/sqlite"
require "logstash/codecs/plain"

describe LogStash::Inputs::Sqlite do
describe "stopping" do
let(:config) { {"path" => "testdb.sqlite3"} }
it_behaves_like "an interruptible input plugin"
end
end

0 comments on commit cb332d2

Please sign in to comment.