lib/deputy.rb in deputy-0.1.6 vs lib/deputy.rb in deputy-0.1.7
- old
+ new
@@ -19,20 +19,20 @@
end
def self.plugins(code)
eval_and_fetch_constants(code).map do |container|
interval = container.interval
- next unless plugin = plugin_in_container(container)
+ unless plugin = plugin_in_container(container)
+ Deputy.send_report "Deputies.Plugin not found", code
+ next
+ end
[interval, plugin]
end.compact
end
def self.plugin_in_container(container)
- constants = container.constants.map{|constant_name| container.const_get(constant_name)}
- constants.detect do |constant|
- constant.instance_methods.map{|m| m.to_sym }.include?(:build_report)
- end
+ container.constants.map{|constant_name| container.const_get(constant_name)}.first
end
end
module Deputy
START_MINUTE = (Time.now.to_i + 30) / 60 # we could start at 58..02 seconds -> always in middle of minute
@@ -42,13 +42,17 @@
`crontab -l | { cat; echo "* * * * * deputy --run-plugins 2>&1 >> /tmp/deputy.log"; } | crontab -`
end
def self.run_plugins
content = get("/plugins.rb")
+
Scout.plugins(content).each do |interval, plugin|
run_every_n_minutes = interval/60
plugin.new.build_report if START_MINUTE % run_every_n_minutes == 0
end
+ rescue Exception => e
+ send_report "Deputies.Error", e.message
+ raise e
end
def self.send_report(metric, value)
get "/report/#{CGI.escape metric}/#{CGI.escape value.to_s}"
end
\ No newline at end of file