diff options
author | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-03-04 10:38:24 +0000 |
---|---|---|
committer | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-03-04 10:38:24 +0000 |
commit | 239829d669857a929cbd68a25dca3bd7c7b91822 (patch) | |
tree | 2b784e00fb95f49c148383d9d456530f4d1a6541 | |
parent | 2202611d8fbaed16739cb37b7f51c9c4b8beaced (diff) |
Added jobs-path argument
-rw-r--r-- | lib/longboat/config.rb | 3 | ||||
-rw-r--r-- | lib/longboat/jobs.rb | 18 | ||||
-rwxr-xr-x | longboat | 1 |
3 files changed, 12 insertions, 10 deletions
diff --git a/lib/longboat/config.rb b/lib/longboat/config.rb index 8f4907c..3fd1510 100644 --- a/lib/longboat/config.rb +++ b/lib/longboat/config.rb @@ -8,7 +8,8 @@ module Longboat opt :collect_every, "Collection interval", type: Integer, default: 60 # Job data - opt :metric_prefix, "Prefix for metric names", type: String, default: "longboat_" + opt :jobs_path, "Paths to search for jobs", type: String, default: "./lib/jobs", multi: true + opt :metric_prefix, "Prefix for metric names", type: String, default: "longboat_" # Sinatra server opt :server_bind, "Server listening address", type: String, default: "127.0.0.1:8564" diff --git a/lib/longboat/jobs.rb b/lib/longboat/jobs.rb index f0ada5a..5166993 100644 --- a/lib/longboat/jobs.rb +++ b/lib/longboat/jobs.rb @@ -4,17 +4,19 @@ module Longboat @collector = collector @jobs = [] @config = config - end - def load! - Dir.entries("./lib/jobs/").each do |file| - next if file =~ /^\./ + @config[:jobs_path].each do |dir| + next unless Dir.exist?(dir) + + Dir.entries(dir).each do |file| + next if file =~ /^\./ - reqname = File.basename(file, ".rb") - cname = reqname.split('_').map(&:capitalize).join + reqname = File.basename(file, ".rb") + cname = reqname.split('_').map(&:capitalize).join - require "jobs/#{reqname}" - @jobs << Kernel.const_get(cname).new(@collector, job_config) + require "jobs/#{reqname}" + @jobs << Kernel.const_get(cname).new(@collector, job_config) + end end end @@ -9,7 +9,6 @@ config = Longboat::Config.parse! # Start collection collector = Longboat::Collector.new(config) jobs = Longboat::Jobs.new(collector, config) -jobs.load! t = jobs.collect_every # Serve metrics on HTTP |