diff options
Diffstat (limited to 'lib/longboat')
-rw-r--r-- | lib/longboat/config.rb | 3 | ||||
-rw-r--r-- | lib/longboat/jobs.rb | 18 |
2 files changed, 12 insertions, 9 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 |