Class: JobTick::Client

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

Constant Summary collapse

PING_PREFIX =
"/ping/"
SYNC_PATH =
"/monitors/sync"

Instance Method Summary collapse

Instance Method Details

#ping(monitor_key, status:, duration: nil, message: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/jobtick/client.rb', line 10

def ping(monitor_key, status:, duration: nil, message: nil)
  config = JobTick.config
  return unless config.enabled && !config.api_key.nil?

  payload = { status: status }
  payload[:duration] = duration.round(3) if duration
  payload[:message]  = message           if message

  Dispatcher.enqueue("#{PING_PREFIX}#{monitor_key}", payload)
end

#register(monitors, app_name: nil, prune: false) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/jobtick/client.rb', line 21

def register(monitors, app_name: nil, prune: false)
  config = JobTick.config
  return unless config.enabled && !config.api_key.nil?

  payload = { monitors: monitors }
  payload[:app_name] = app_name if app_name && !app_name.empty?
  payload[:prune]    = true if prune

  Dispatcher.send_sync(SYNC_PATH, payload)
end