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.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/backup/notifier/base.rb', line 48 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 ||= lambda do |m, data| "[#{data[:status][:message]}] #{m.label} (#{m.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
30 31 32 |
# File 'lib/backup/notifier/base.rb', line 30 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 })”
44 45 46 |
# File 'lib/backup/notifier/base.rb', line 44 def end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
46 47 48 |
# File 'lib/backup/notifier/base.rb', line 46 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
24 25 26 |
# File 'lib/backup/notifier/base.rb', line 24 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
12 13 14 |
# File 'lib/backup/notifier/base.rb', line 12 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
18 19 20 |
# File 'lib/backup/notifier/base.rb', line 18 def on_warning @on_warning end |
#retry_waitsec ⇒ Object
Time in seconds to pause before each retry. Default: 30
35 36 37 |
# File 'lib/backup/notifier/base.rb', line 35 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.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/backup/notifier/base.rb', line 65 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 |