class StatsCloud::RegisterConnectionJob

Registers StatsCloud connection.

Constants

ERROR_CODES

Attributes

app[R]
cluster_client[R]
tags[R]
token[R]

Public Class Methods

new(cluster_client, token, app, tags) click to toggle source
# File lib/statscloud/jobs/register_connection_job.rb, line 14
def initialize(cluster_client, token, app, tags)
  @cluster_client = cluster_client
  @token = token
  @app = app
  @tags = tags
  @job_running = false
end

Public Instance Methods

start() click to toggle source
# File lib/statscloud/jobs/register_connection_job.rb, line 22
def start
  Thread.new do
    event_machine.run do
      event_machine.add_periodic_timer(3600) { run_job }
    end
  end.join
end

Private Instance Methods

check_for_errors(response) click to toggle source
# File lib/statscloud/jobs/register_connection_job.rb, line 52
def check_for_errors(response)
  log_register_connection_error(response.body) if ERROR_CODES.include?(response.code)
end
event_machine() click to toggle source
# File lib/statscloud/jobs/register_connection_job.rb, line 60
def event_machine
  EventMachine
end
log_register_connection_error(response_body) click to toggle source
# File lib/statscloud/jobs/register_connection_job.rb, line 56
def log_register_connection_error(response_body)
  log_error response_body[:message]
end
run_job() click to toggle source
# File lib/statscloud/jobs/register_connection_job.rb, line 34
def run_job
  return if @job_running

  start_running
  connection_response = cluster_client.register_statscloud_connection(token, app, tags)
  return stop_running if connection_response.code == 204

  check_for_errors(connection_response)
end
start_running() click to toggle source
# File lib/statscloud/jobs/register_connection_job.rb, line 44
def start_running
  @job_running = true
end
stop_running() click to toggle source
# File lib/statscloud/jobs/register_connection_job.rb, line 48
def stop_running
  @job_running = false
end