Class: HR_Deploy::CheckHerokuTask

Inherits:
Task
  • Object
show all
Defined in:
lib/hr_deploy/tasks/check_heroku_task.rb

Instance Attribute Summary

Attributes inherited from Task

#end_time, #error, #start_time

Instance Method Summary collapse

Methods inherited from Task

#initialize, #reversal_instruction, #successful?

Constructor Details

This class inherits a constructor from HR_Deploy::Task

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/hr_deploy/tasks/check_heroku_task.rb', line 11

def run
  print_stage 'Checking Heroku status...'

  if dry_run?
    self.success = true
    return
  end

  uri = URI.parse('https://status.heroku.com/api/v3/current-status')

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Get.new(uri.request_uri)

  begin
    response = http.request(request)

  rescue
    self.success = false
    self.error = 'Could not fetch Heroku status'

  else
    if response.code == '200'

      status = JSON.parse(response.body)
      status = status['status'] if status

      if status && status['Production'] && status['Development']

        production_ok = status['Production'] == 'green'
        development_ok = status['Development'] == 'green'

        if production_ok && development_ok
          print_success 'Heroku is operating correctly'
          self.success = true
        else
          self.success = false
          self.error = 'Heroku is having problems'
        end
      else

        self.success = false
        self.error = 'Could not parse Heroku status'
      end

    else
      self.success = false
      self.error = 'Could not fetch Heroku status'
    end
  end
end