Skip to content

Commit

Permalink
Merge pull request #2852 from FireLemons/store_and_display_time_of_la…
Browse files Browse the repository at this point in the history
…test_deploy

Store and display time of latest deploy attempt #4
  • Loading branch information
FireLemons committed Oct 28, 2021
2 parents 50e5062 + 83001e9 commit 83b86e2
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
7 changes: 1 addition & 6 deletions app/controllers/health_controller.rb
Expand Up @@ -2,11 +2,6 @@ class HealthController < ApplicationController
skip_before_action :authenticate_user!

def index
unless Rails.application.config.respond_to?(:latest_deploy_time)

Rails.application.config.latest_deploy_time = JSON.parse(File.read(Rails.root.join("tmp", "deploy_time.json").to_s))["latest_deploy_time"]
end

render json: {latest_deploy_time: Rails.application.config.latest_deploy_time}
render json: {latest_deploy_time: Health.instance.latest_deploy_time}
end
end
24 changes: 24 additions & 0 deletions app/models/health.rb
@@ -0,0 +1,24 @@
class Health < ApplicationRecord
# The "singleton_guard" column is a unique column which must always be set to '0'
# This ensures that only one Health row is created
validates_inclusion_of :singleton_guard, in: [0]

def self.instance
first_or_create!(singleton_guard: 0)
end
end

# == Schema Information
#
# Table name: healths
#
# id :bigint not null, primary key
# latest_deploy_time :datetime
# singleton_guard :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_healths_on_singleton_guard (singleton_guard) UNIQUE
#
12 changes: 12 additions & 0 deletions db/migrate/20211025143709_create_healths.rb
@@ -0,0 +1,12 @@
class CreateHealths < ActiveRecord::Migration[6.1]
def change
create_table :healths do |t|
t.timestamp :latest_deploy_time
t.integer :singleton_guard

t.timestamps
end

add_index(:healths, :singleton_guard, unique: true)
end
end
10 changes: 9 additions & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_10_12_180102) do
ActiveRecord::Schema.define(version: 2021_10_25_143709) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -229,6 +229,14 @@
t.index ["creator_id"], name: "index_followups_on_creator_id"
end

create_table "healths", force: :cascade do |t|
t.datetime "latest_deploy_time"
t.integer "singleton_guard"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["singleton_guard"], name: "index_healths_on_singleton_guard", unique: true
end

create_table "hearing_types", force: :cascade do |t|
t.bigint "casa_org_id", null: false
t.string "name", null: false
Expand Down
6 changes: 1 addition & 5 deletions lib/tasks/deployment/20211023145114_store_deploy_time.rake
Expand Up @@ -3,10 +3,6 @@ namespace :after_party do
task store_deploy_time: :environment do
puts "Running deploy task 'store_deploy_time'"

FileUtils.mkdir_p Rails.root.join("tmp")

File.open(Rails.root.join("tmp", "deploy_time.json"), "w") do |f|
f.write({latest_deploy_time: Time.now.utc.iso8601}.to_json)
end
Health.instance.update_attribute(:latest_deploy_time, Time.now)
end
end
6 changes: 6 additions & 0 deletions spec/factories/healths.rb
@@ -0,0 +1,6 @@
FactoryBot.define do
factory :health do
latest_deploy_time { Time.now }
singleton_guard { 0 }
end
end
5 changes: 5 additions & 0 deletions spec/models/health_spec.rb
@@ -0,0 +1,5 @@
require "rails_helper"

RSpec.describe Health, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 83b86e2

Please sign in to comment.