This repository was archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 570
Expand file tree
/
Copy pathapplication.rb
More file actions
100 lines (76 loc) · 3.06 KB
/
Copy pathapplication.rb
File metadata and controls
100 lines (76 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# frozen_string_literal: true
require_relative "boot"
require "rails/all"
require "csv"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
ENV["FAILBOT_BACKEND"] ||= "memory"
# report exceptions using Failbot
require "failbot_rails"
FailbotRails.setup("classroom#{'-staging' if Rails.env.staging?}")
module GitHubClassroom
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**", "*.{rb,yml}")]
# Available locales
I18n.available_locales = [:en]
# Append directories to autoload paths
config.eager_load_paths += %w[lib].map { |path| Rails.root.join(path).to_s }
# Configure the generators
config.generators do |g|
g.test_framework :rspec, fixture: false
end
# GC Profiler for analytics
GC::Profiler.enable
# Use SideKiq for background jobs
config.active_job.queue_adapter = :sidekiq
# Health checks endpoint for monitoring
if ENV["PINGLISH_ENABLED"] == "true"
# rubocop:disable Metrics/BlockLength
config.middleware.use Pinglish do |ping|
ping.check :db do
ActiveRecord::Base.connection.tables.size
"ok"
end
ping.check :memcached do
Rails.cache.dalli.checkout.alive!
"ok"
end
ping.check :redis do
Sidekiq.redis(&:ping)
"ok"
end
ping.check :github, timeout: 5 do
uri = URI("https://www.githubstatus.com/api/v2/components.json")
status_components = JSON.parse(Net::HTTP.get(uri))["components"]
raise "GitHub status format is invalid!" if status_components.blank?
github_status_api_id = "brv1bkgrwx7q"
api_component = status_components.find do |component|
component["id"] == github_status_api_id
end
raise "GitHub API status ID (#{github_status_api_id}) cannot be found!" if api_component.blank?
api_status = api_component["status"]
raise "GitHub API status is #{status}" if api_status != "operational"
"ok"
end
ping.check :github_api, timeout: 5 do
client = GitHubClassroom.github_client
rate_limit = client.rate_limit
status = client.last_response.status
raise "GitHub API status is #{status}" if status != 200
if rate_limit.remaining < 10
raise "Low rate limit. #{rate_limit.remaining} remaining, resets in #{rate_limit.resets_in}"
end
"ok"
end
end
# rubocop:enable Metrics/BlockLength
end
end
end