Class: JobTick::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/jobtick/monitor.rb

Constant Summary collapse

MONOTONIC =
Process::CLOCK_MONOTONIC

Class Method Summary collapse

Class Method Details

.run(key) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jobtick/monitor.rb', line 7

def self.run(key)
  config = JobTick.config
  return yield unless config.enabled && !config.api_key.nil?

  client = JobTick.client
  client.ping(key, status: :started)
  started = Process.clock_gettime(MONOTONIC)
  result  = yield
  duration = Process.clock_gettime(MONOTONIC) - started
  client.ping(key, status: :completed, duration: duration)
  result
rescue StandardError => e
  JobTick.client.ping(key, status: :failed, message: e.message)
  raise
end