about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-04-05 14:31:07 +0200
committerClaire <claire.github-309c@sitedethib.com>2021-04-05 14:31:07 +0200
commitc901ae77d43bc76afc5c927c82b9b75609fa3a58 (patch)
tree41ccfe01da595433ef64e229a767ac62b7adfd92 /app/lib
parent39b9a0619ab4ba68ed429152153cf0dbbfcd5a5a (diff)
parent117f6638d0c402162c60915c7b8946489f1e89df (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/admin/system_check.rb21
-rw-r--r--app/lib/admin/system_check/base_check.rb11
-rw-r--r--app/lib/admin/system_check/database_schema_check.rb11
-rw-r--r--app/lib/admin/system_check/message.rb11
-rw-r--r--app/lib/admin/system_check/rules_check.rb13
-rw-r--r--app/lib/admin/system_check/sidekiq_process_check.rb26
6 files changed, 93 insertions, 0 deletions
diff --git a/app/lib/admin/system_check.rb b/app/lib/admin/system_check.rb
new file mode 100644
index 000000000..afb20cb47
--- /dev/null
+++ b/app/lib/admin/system_check.rb
@@ -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
diff --git a/app/lib/admin/system_check/base_check.rb b/app/lib/admin/system_check/base_check.rb
new file mode 100644
index 000000000..fcad8daca
--- /dev/null
+++ b/app/lib/admin/system_check/base_check.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class Admin::SystemCheck::BaseCheck
+  def pass?
+    raise NotImplementedError
+  end
+
+  def message
+    raise NotImplementedError
+  end
+end
diff --git a/app/lib/admin/system_check/database_schema_check.rb b/app/lib/admin/system_check/database_schema_check.rb
new file mode 100644
index 000000000..b93d1954e
--- /dev/null
+++ b/app/lib/admin/system_check/database_schema_check.rb
@@ -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
diff --git a/app/lib/admin/system_check/message.rb b/app/lib/admin/system_check/message.rb
new file mode 100644
index 000000000..bfcad3bf3
--- /dev/null
+++ b/app/lib/admin/system_check/message.rb
@@ -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
diff --git a/app/lib/admin/system_check/rules_check.rb b/app/lib/admin/system_check/rules_check.rb
new file mode 100644
index 000000000..1fbdf955d
--- /dev/null
+++ b/app/lib/admin/system_check/rules_check.rb
@@ -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
diff --git a/app/lib/admin/system_check/sidekiq_process_check.rb b/app/lib/admin/system_check/sidekiq_process_check.rb
new file mode 100644
index 000000000..c44d86c44
--- /dev/null
+++ b/app/lib/admin/system_check/sidekiq_process_check.rb
@@ -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