module ProbyNotifier
Constants
- BASE_URL
- VERSION
Public Class Methods
api_key=(api_key)
click to toggle source
Set your Proby API key.
@param [String] api_key Your Proby API key
@example
ProbyNotifier.api_key = '1234567890abcdefg'
# File lib/proby_notifier/proby_notifier.rb, line 17 def api_key=(api_key) @api_key = api_key end
logger()
click to toggle source
Get the logger used by Proby.
# File lib/proby_notifier/proby_notifier.rb, line 33 def logger @logger || Logger.new("/dev/null") end
logger=(logger)
click to toggle source
Set the logger to be used by Proby.
@param [Logger] logger The logger you would like ProbyNotifier
to use
@example
ProbyNotifier.logger = Rails.logger ProbyNotifier.logger = Logger.new(STDERR)
# File lib/proby_notifier/proby_notifier.rb, line 28 def logger=(logger) @logger = logger end
send_finish_notification(proby_task_id=nil, options={})
click to toggle source
Send a finish notification for this task to Proby
@param [String] proby_task_id The id of the task to be notified. If nil, the
value of the +PROBY_TASK_ID+ environment variable will be used.
@param [Hash] options The options for the finish notification @option options [Boolean] :failed true if this task run resulted in some sort of failure. Setting
this parameter to true will trigger a notification to be sent to the alarms configured for the given task. Defaults to false.
@option options [String] :error_message A string message describing the failure that occurred.
1,000 character limit.
# File lib/proby_notifier/proby_notifier.rb, line 55 def send_finish_notification(proby_task_id=nil, options={}) send_notification('/finish', proby_task_id, options) end
send_start_notification(proby_task_id=nil)
click to toggle source
Send a start notification for this task to Proby.
@param [String] proby_task_id The id of the task to be notified. If nil, the
value of the +PROBY_TASK_ID+ environment variable will be used.
# File lib/proby_notifier/proby_notifier.rb, line 41 def send_start_notification(proby_task_id=nil) send_notification('/start', proby_task_id) end
Private Class Methods
is_blank?(string)
click to toggle source
# File lib/proby_notifier/proby_notifier.rb, line 90 def is_blank?(string) string.nil? || string.strip == '' end
send_notification(type, proby_task_id, options={})
click to toggle source
# File lib/proby_notifier/proby_notifier.rb, line 61 def send_notification(type, proby_task_id, options={}) if @api_key.nil? logger.warn "ProbyNotifier: No notification sent because API key is not set" return nil end proby_task_id = ENV['PROBY_TASK_ID'] if is_blank?(proby_task_id) if is_blank?(proby_task_id) logger.warn "ProbyNotifier: No notification sent because task ID was not specified" return nil end url = BASE_URL + proby_task_id + type uri = URI.parse(url) req = Net::HTTP::Post.new(uri.path, {'api_key' => @api_key}) req.set_form_data(options) http = Net::HTTP.new(uri.host, uri.port) http.open_timeout = 3 http.read_timeout = 3 http.use_ssl = true res = http.start { |h| h.request(req) } return res.code.to_i rescue Exception => e logger.error "ProbyNotifier: Proby notification failed: #{e.message}" logger.error e.backtrace end