diff options
Diffstat (limited to 'lib/longboat/jobs.rb')
-rw-r--r-- | lib/longboat/jobs.rb | 41 |
1 files changed, 41 insertions, 0 deletions
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 |