class TrackerHub::Request::Notification
Notify a configured service when an error occured during the request log process
Constants
- KEY_CACHE
Key to cache the timelapse between 2 notifications
Attributes
@return [Object] the notification adapter @api public
@return [Hash] notification and notifier options @api public
@return [Integer|ActiveSupport::Duration] timelapse between 2 notifications @api public
Public Class Methods
Instantiate a notification object to add the ability to send a notification
to any service adapter (see in request/notification). If a timelapse is given in parameter, there will be a pause between 2 notifications. Please checkout the available adapters for more :args: options
@param [Object] notifier The notification adapter @option args [Integer] :timelapse Time between 2 notifications
@example
> notifier = TrackerHub::Request::Notification::HipChat.new(token, 'room', 'username') > options = { timelapse: 10.minutes } > TrackerHub::Request::Notification.new(notifier, options)
@api private
# File lib/tracker_hub/request/notification.rb, line 71 def initialize(notifier = nil, args = {}) defaults = { notify: true } self.notifier = notifier self.timelapse = args.delete(:timelapse) self.options = defaults.merge(args) end
Public Instance Methods
Trigger a notification paused by a timelapse if specified
@param [String] message Notification's message @param [Hash] args Notifier adapter's options (if there is any) @return [undefined]
@example
> notifier = TrackerHub::Request::Notification::HipChat.new(token, 'room', 'username') > options = { timelapse: 10.minutes } > notification = TrackerHub::Request::Notification.new(notifier, options) > notification.notify('my message')
@api public
# File lib/tracker_hub/request/notification.rb, line 35 def notify(message, args = {}) timelapser do notifier.send_message(message, options.merge(args)) end rescue false end
Private Instance Methods
Execute an action in a timelapse
@return [Boolean]
@api private
# File lib/tracker_hub/request/notification.rb, line 86 def timelapser return yield unless timelapse Rails.cache.fetch(KEY_CACHE, expires_in: timelapse) do yield end end