Class: SidekiqVigil::Alert::Mute
- Inherits:
-
Object
- Object
- SidekiqVigil::Alert::Mute
- Defined in:
- lib/sidekiq_vigil/alert/mute.rb
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#initialize(storage:, schedules: [], clock: -> { Time.now }, timezone: "UTC") ⇒ Mute
constructor
A new instance of Mute.
- #mute(duration, reason: nil) ⇒ Object
- #reason ⇒ Object
- #unmute ⇒ Object
Constructor Details
#initialize(storage:, schedules: [], clock: -> { Time.now }, timezone: "UTC") ⇒ Mute
Returns a new instance of Mute.
8 9 10 11 12 13 |
# File 'lib/sidekiq_vigil/alert/mute.rb', line 8 def initialize(storage:, schedules: [], clock: -> { Time.now }, timezone: "UTC") @storage = storage @schedules = schedules @clock = clock @timezone = timezone end |
Instance Method Details
#active? ⇒ Boolean
15 16 17 |
# File 'lib/sidekiq_vigil/alert/mute.rb', line 15 def active? !reason.nil? end |
#mute(duration, reason: nil) ⇒ Object
23 24 25 26 |
# File 'lib/sidekiq_vigil/alert/mute.rb', line 23 def mute(duration, reason: nil) payload = JSON.generate(reason: reason || "manual mute", until: clock.call.to_f + duration) storage.set("mute", payload, ttl: duration) end |
#reason ⇒ Object
19 20 21 |
# File 'lib/sidekiq_vigil/alert/mute.rb', line 19 def reason dynamic_reason || scheduled_reason end |
#unmute ⇒ Object
28 29 30 |
# File 'lib/sidekiq_vigil/alert/mute.rb', line 28 def unmute storage.delete("mute") end |