Class: RooOnRails::Checks::Papertrail::SystemExists

Inherits:
EnvSpecific show all
Defined in:
lib/roo_on_rails/checks/papertrail/system_exists.rb

Overview

Checks that the app is declared in Papertrail

Input context

  • heroku.api_client: a connected PlatformAPI client

  • heroku.app.EnvSpecific#env: an existing app name.

  • papertrail.system_name.EnvSpecific#env: a Papertrail system name / token

  • papertrail.client

  • papertrail.dest.host, .port

Output context:

Instance Attribute Summary

Attributes inherited from EnvSpecific

#env

Instance Method Summary collapse

Methods inherited from EnvSpecific

#initialize, #signature

Methods inherited from Base

#initialize, requires, #run

Methods included from Helpers

#bold, included

Constructor Details

This class inherits a constructor from RooOnRails::Checks::EnvSpecific

Instance Method Details

#callObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/roo_on_rails/checks/papertrail/system_exists.rb', line 32

def call
  data = context.papertrail.client.list_systems.find { |h|
    h['hostname'] == system_token
  }
  fail! "no system with token '#{system_token}' found on #{bold app_name}" if data.nil?

  if data.syslog.hostname != context.papertrail.dest.host ||
     data.syslog.port != context.papertrail.dest.port
    final_fail! "system found, but is listening to #{data.syslog.hostname}:#{data.syslog.port} instead of #{context.papertrail.dest.host}:#{context.papertrail.dest.port}"
  end

  context.papertrail.system_id![env] = data.id
  pass "found system #{data.id} for token #{system_token}"
end

#fixObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/roo_on_rails/checks/papertrail/system_exists.rb', line 47

def fix
  # cause the app to log something
  dyno = heroku.dyno.create(app_name, command: 'date')

  # wait a bit
  10.times do
    begin
      heroku.dyno.info(app_name, dyno['id'])
      sleep 0.5
    rescue Excon::Error::NotFound
      break
    end
  end
end

#introObject



28
29
30
# File 'lib/roo_on_rails/checks/papertrail/system_exists.rb', line 28

def intro
  'Checking that the app is logging to Papertrail...'
end