Module: GetaroundUtils::Engines::Health

Defined in:
lib/getaround_utils/engines/health.rb

Constant Summary collapse

RELEASE_VERSION_PATH =
'/release_version'
COMMIT_SHA1_PATH =
'/commit_sha1'
MIGRATION_STATUS_PATH =
'/migration_status'
UNDEFINED =
'N/A'

Class Method Summary collapse

Class Method Details

.commit_sha1Object



20
21
22
# File 'lib/getaround_utils/engines/health.rb', line 20

def self.commit_sha1
  ENV['HEROKU_SLUG_COMMIT'] || ENV['COMMIT_SHA1']
end

.engineObject



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
63
64
65
66
67
68
69
70
71
72
# File 'lib/getaround_utils/engines/health.rb', line 34

def self.engine
  Rack::Builder.new do
    map RELEASE_VERSION_PATH do
      use Rack::Head

      run(lambda do |env|
        req = Rack::Request.new(env)
        return [405, { 'Content-Type' => 'text/plain' }, []] unless req.get?

        content = GetaroundUtils::Engines::Health.release_version || UNDEFINED
        [200, { 'Content-Type' => 'text/plain' }, [content]]
      end)
    end

    map COMMIT_SHA1_PATH do
      use Rack::Head

      run(lambda do |env|
        req = Rack::Request.new(env)
        return [405, { 'Content-Type' => 'text/plain' }, []] unless req.get?

        content = GetaroundUtils::Engines::Health.commit_sha1 || UNDEFINED
        [200, { 'Content-Type' => 'text/plain' }, [content]]
      end)
    end

    map MIGRATION_STATUS_PATH do
      use Rack::Head

      run(lambda do |env|
        req = Rack::Request.new(env)
        return [405, { 'Content-Type' => 'application/json' }, []] unless req.get?

        content = { needs_migration: GetaroundUtils::Engines::Health.needs_migration? }
        [200, { 'Content-Type' => 'application/json' }, [JSON.generate(content)]]
      end)
    end
  end
end

.needs_migration?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
# File 'lib/getaround_utils/engines/health.rb', line 24

def self.needs_migration?
  return false unless defined?(ActiveRecord)

  if Gem.loaded_specs["activerecord"].version < Gem::Version.create("7.2.1")
    ActiveRecord::Base.connection.migration_context.needs_migration?
  else
    ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths).needs_migration?
  end
end

.release_versionObject



16
17
18
# File 'lib/getaround_utils/engines/health.rb', line 16

def self.release_version
  ENV['HEROKU_RELEASE_VERSION'] || ENV['PORTER_STACK_REVISION'] || ENV['PORTER_POD_REVISION']
end