Class: SidekiqVigil::Check::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_vigil/check/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage:, options: {}, clock: -> { Time.now }, logger: SidekiqVigil.logger, api: SidekiqApi.new) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
# File 'lib/sidekiq_vigil/check/base.rb', line 8

def initialize(storage:, options: {}, clock: -> { Time.now }, logger: SidekiqVigil.logger, api: SidekiqApi.new)
  @storage = storage
  @options = options
  @clock = clock
  @logger = logger
  @api = api
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



6
7
8
# File 'lib/sidekiq_vigil/check/base.rb', line 6

def api
  @api
end

#clockObject (readonly)

Returns the value of attribute clock.



6
7
8
# File 'lib/sidekiq_vigil/check/base.rb', line 6

def clock
  @clock
end

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/sidekiq_vigil/check/base.rb', line 6

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/sidekiq_vigil/check/base.rb', line 6

def options
  @options
end

#storageObject (readonly)

Returns the value of attribute storage.



6
7
8
# File 'lib/sidekiq_vigil/check/base.rb', line 6

def storage
  @storage
end

Instance Method Details

#callObject

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/sidekiq_vigil/check/base.rb', line 28

def call
  raise NotImplementedError, "#{self.class} must implement #call"
end

#check_nameObject



32
33
34
35
# File 'lib/sidekiq_vigil/check/base.rb', line 32

def check_name
  class_name = self.class.name || "custom_check"
  class_name.split("::").last.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
end

#executeObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sidekiq_vigil/check/base.rb', line 16

def execute
  Array(call)
rescue StandardError => e
  logger.error("[sidekiq-vigil] #{check_name} failed: #{e.class}: #{e.message}")
  [Result.new(
    check_name:,
    severity: :error,
    message: "#{e.class}: #{e.message}",
    metadata: { exception_class: e.class.name }
  )]
end