Class: Backup::Notifier::Base
- Inherits:
-
Object
- Object
- Backup::Notifier::Base
- Includes:
- Config::Helpers, Utilities::Helpers
- Defined in:
- lib/backup/notifier/base.rb
Direct Known Subclasses
Campfire, Command, DataDog, FlowDock, Hipchat, HttpPost, Mail, Nagios, PagerDuty, Prowl, Pushover, Ses, Slack, Twitter, Zabbix
Instance Attribute Summary collapse
-
#max_retries ⇒ Object
Number of times to retry failed attempts to send notification.
-
#message {|Backup::Model, Hash| ... } ⇒ Object
Message to send.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#on_failure ⇒ Object
(also: #notify_on_failure?)
When set to true, the user will be notified by email when a backup process raises an exception before finishing.
-
#on_success ⇒ Object
(also: #notify_on_success?)
When set to true, the user will be notified by email when a backup process ends without raising any exceptions.
-
#on_warning ⇒ Object
(also: #notify_on_warning?)
When set to true, the user will be notified by email when a backup process is successful, but has warnings.
-
#retry_waitsec ⇒ Object
Time in seconds to pause before each retry.
Instance Method Summary collapse
-
#initialize(model) ⇒ Base
constructor
A new instance of Base.
-
#perform! ⇒ Object
This method is called from an ensure block in Model#perform! and must not raise any exceptions.
Methods included from Config::Helpers
Constructor Details
#initialize(model) ⇒ Base
Returns a new instance of Base.
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/backup/notifier/base.rb', line 50 def initialize(model) @model = model load_defaults! @on_success = true if on_success.nil? @on_warning = true if on_warning.nil? @on_failure = true if on_failure.nil? @max_retries ||= 10 @retry_waitsec ||= 30 @message ||= lambda do |model, data| "[#{ data[:status][:message] }] #{ model.label } (#{ model.trigger })" end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Backup::Config::Helpers
Instance Attribute Details
#max_retries ⇒ Object
Number of times to retry failed attempts to send notification. Default: 10
32 33 34 |
# File 'lib/backup/notifier/base.rb', line 32 def max_retries @max_retries end |
#message {|Backup::Model, Hash| ... } ⇒ Object
Message to send. Depends on notifier implementation if this is used. Default: lambda returning: “#{ message } #{ model.label } (#{ model.trigger })”
46 47 48 |
# File 'lib/backup/notifier/base.rb', line 46 def @message end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
48 49 50 |
# File 'lib/backup/notifier/base.rb', line 48 def model @model end |
#on_failure ⇒ Object Also known as: notify_on_failure?
When set to true, the user will be notified by email when a backup process raises an exception before finishing
26 27 28 |
# File 'lib/backup/notifier/base.rb', line 26 def on_failure @on_failure end |
#on_success ⇒ Object Also known as: notify_on_success?
When set to true, the user will be notified by email when a backup process ends without raising any exceptions
14 15 16 |
# File 'lib/backup/notifier/base.rb', line 14 def on_success @on_success end |
#on_warning ⇒ Object Also known as: notify_on_warning?
When set to true, the user will be notified by email when a backup process is successful, but has warnings
20 21 22 |
# File 'lib/backup/notifier/base.rb', line 20 def on_warning @on_warning end |
#retry_waitsec ⇒ Object
Time in seconds to pause before each retry. Default: 30
37 38 39 |
# File 'lib/backup/notifier/base.rb', line 37 def retry_waitsec @retry_waitsec end |
Instance Method Details
#perform! ⇒ Object
This method is called from an ensure block in Model#perform! and must not raise any exceptions. However, each Notifier’s #notify! method should raise an exception if the request fails so it may be retried.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/backup/notifier/base.rb', line 67 def perform! status = case model.exit_status when 0 :success if notify_on_success? when 1 :warning if notify_on_success? || notify_on_warning? else :failure if notify_on_failure? end if status Logger.info "Sending notification using #{ notifier_name }..." with_retries { notify!(status) } end rescue Exception => err Logger.error Error.wrap(err, "#{ notifier_name } Failed!") end |