lib/logstash/inputs/yasuri.rb in logstash-input-yasuri-5.0.4 vs lib/logstash/inputs/yasuri.rb in logstash-input-yasuri-5.0.5
- old
+ new
@@ -1,9 +1,10 @@
# encoding: utf-8
require "logstash/inputs/base"
require "logstash/namespace"
require "socket" # for Socket.gethostname
+require "rufus-scheduler"
require "mechanize"
require "yasuri"
class LogStash::Inputs::Yasuri < LogStash::Inputs::Base
config_name "yasuri"
@@ -24,40 +25,41 @@
config :url, :validate => :string
# Split each results to individual events (struct or pages)
config :split, :default => false
- config :interval, :validate => :number, :default => 60
+ config :cron, :validate => :string, :default => '* * * * *'
public
def register
@host = Socket.gethostname
@agent = Mechanize.new
+ @scheduler = Rufus::Scheduler.new
# If given both, logstash-input-yasuri use :parse_tree.
tree = @parse_tree || File.read(@parse_tree_path)
@tree = Yasuri.json2tree(tree)
end # def register
def run(queue)
# we can abort the loop if stop? becomes true
- while !stop?
+ scheduler.cron @cron do
# because the sleep interval can be big, when shutdown happens
# we want to be able to abort the sleep
# Stud.stoppable_sleep will frequently evaluate the given block
# and abort the sleep(@interval) if the return value is true
inner_run(queue)
- Stud.stoppable_sleep(@interval) { stop? }
- end # loop
+ end
end # def run
def stop
# nothing to do in this case so it is not necessary to define stop
# examples of common "stop" tasks:
# * close sockets (unblocking blocking reads/accepts)
# * cleanup temporary files
# * terminate spawned threads
+ @scheduler.shutdown
end
def inner_run(queue)
parsed = scrape()
elements = if @split