Class: TrackerHub::Request::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/tracker_hub/request/notification.rb,
lib/tracker_hub/request/notification/hip_chat.rb

Overview

Notify a configured service when an error occured during the request log process

Defined Under Namespace

Classes: HipChat

Constant Summary collapse

KEY_CACHE =

Key to cache the timelapse between 2 notifications

'trackinghub_request_notification'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#notifierObject

Returns the notification adapter.

Returns:

  • (Object)

    the notification adapter



12
13
14
# File 'lib/tracker_hub/request/notification.rb', line 12

def notifier
  @notifier
end

#optionsHash

Returns notification and notifier options.

Returns:

  • (Hash)

    notification and notifier options



20
21
22
# File 'lib/tracker_hub/request/notification.rb', line 20

def options
  @options
end

#timelapseInteger|ActiveSupport::Duration

Returns timelapse between 2 notifications.

Returns:

  • (Integer|ActiveSupport::Duration)

    timelapse between 2 notifications



16
17
18
# File 'lib/tracker_hub/request/notification.rb', line 16

def timelapse
  @timelapse
end

Instance Method Details

#notify(message, args = {}) ⇒ undefined

Trigger a notification paused by a timelapse if specified

Examples:

> notifier = TrackerHub::Request::Notification::HipChat.new(token, 'room', 'username')
> options = { timelapse: 10.minutes }
> notification = TrackerHub::Request::Notification.new(notifier, options)
> notification.notify('my message')

Parameters:

  • message (String)

    Notification’s message

  • args (Hash) (defaults to: {})

    Notifier adapter’s options (if there is any)

Returns:

  • (undefined)


35
36
37
38
39
40
41
# 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