forked from glitch-soc/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add system checks to dashboard in admin UI (mastodon#15989)
- Loading branch information
1 parent
ec2bab4
commit 9d47138
Showing
10 changed files
with
152 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class Admin::SystemCheck | ||
ACTIVE_CHECKS = [ | ||
Admin::SystemCheck::DatabaseSchemaCheck, | ||
Admin::SystemCheck::SidekiqProcessCheck, | ||
Admin::SystemCheck::RulesCheck, | ||
].freeze | ||
|
||
def self.perform | ||
ACTIVE_CHECKS.each_with_object([]) do |klass, arr| | ||
check = klass.new | ||
|
||
if check.pass? | ||
arr | ||
else | ||
arr << check.message | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Admin::SystemCheck::BaseCheck | ||
def pass? | ||
raise NotImplementedError | ||
end | ||
|
||
def message | ||
raise NotImplementedError | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Admin::SystemCheck::DatabaseSchemaCheck < Admin::SystemCheck::BaseCheck | ||
def pass? | ||
!ActiveRecord::Base.connection.migration_context.needs_migration? | ||
end | ||
|
||
def message | ||
Admin::SystemCheck::Message.new(:database_schema_check) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Admin::SystemCheck::Message | ||
attr_reader :key, :value, :action | ||
|
||
def initialize(key, value = nil, action = nil) | ||
@key = key | ||
@value = value | ||
@action = action | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class Admin::SystemCheck::RulesCheck < Admin::SystemCheck::BaseCheck | ||
include RoutingHelper | ||
|
||
def pass? | ||
Rule.kept.exists? | ||
end | ||
|
||
def message | ||
Admin::SystemCheck::Message.new(:rules_check, nil, admin_rules_path) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
class Admin::SystemCheck::SidekiqProcessCheck < Admin::SystemCheck::BaseCheck | ||
SIDEKIQ_QUEUES = %w( | ||
default | ||
push | ||
mailers | ||
pull | ||
scheduler | ||
ingress | ||
).freeze | ||
|
||
def pass? | ||
missing_queues.empty? | ||
end | ||
|
||
def message | ||
Admin::SystemCheck::Message.new(:sidekiq_process_check, missing_queues.join(', ')) | ||
end | ||
|
||
private | ||
|
||
def missing_queues | ||
@missing_queues ||= Sidekiq::ProcessSet.new.reduce(SIDEKIQ_QUEUES) { |queues, process| queues - process['queues'] } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters