From 96537e39ae2faa4c7801423055db26b86f875431 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 2 Mar 2020 14:30:43 +0000 Subject: Broke apart job running and metric collection. Jobs are now picked up automagically from lib/jobs --- lib/longboat/jobs.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 lib/longboat/jobs.rb (limited to 'lib/longboat/jobs.rb') diff --git a/lib/longboat/jobs.rb b/lib/longboat/jobs.rb new file mode 100644 index 0000000..155b305 --- /dev/null +++ b/lib/longboat/jobs.rb @@ -0,0 +1,41 @@ +module Longboat + class Jobs + def initialize + @jobs = [] + end + + def load(collector) + Dir.entries("./lib/jobs/").each do |file| + next if file =~ /^\./ + + reqname = File.basename(file, ".rb") + cname = reqname.split('_').map(&:capitalize).join + + require "jobs/#{reqname}" + @jobs << Kernel.const_get(cname).new(collector) + end + end + + def collect! + @jobs.each do |job| + job.run + end + end + + def collect_every(time = 60, async = true) + if async + Thread.new do + loop do + collect! + sleep(time) + end + end + else + loop do + collect! + sleep(time) + end + end + end + end +end -- cgit v1.2.1