Class: SidekiqVigil::Alert::Mute

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_vigil/alert/mute.rb

Instance Method Summary collapse

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

Returns:

  • (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

#reasonObject



19
20
21
# File 'lib/sidekiq_vigil/alert/mute.rb', line 19

def reason
  dynamic_reason || scheduled_reason
end

#unmuteObject



28
29
30
# File 'lib/sidekiq_vigil/alert/mute.rb', line 28

def unmute
  storage.delete("mute")
end