OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Moved all storage health logic from model to health service
Andreas Pfohladd0f8f38f20
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex 4c41131ecea..8901a99b25c 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -113,28 +113,6 @@ module Storagesendend- def mark_as_unhealthy(reason: nil)- if health_status == 'unhealthy' && reason_is_same(reason)- touch(:health_checked_at)- else- update(health_status: 'unhealthy',- health_changed_at: Time.now.utc,- health_checked_at: Time.now.utc,- health_reason: reason)- end- end-- def mark_as_healthy- if health_status == 'healthy'- touch(:health_checked_at)- else- update(health_status: 'healthy',- health_changed_at: Time.now.utc,- health_checked_at: Time.now.utc,- health_reason: nil)- end- end-def automatically_managed?ActiveSupport::Deprecation.warn('`#automatically_managed?` is deprecated. Use `#automatic_management_enabled?` instead. ' \@@ -205,11 +183,5 @@ module Storagesdef health_reason_description@health_reason_description ||= self.class.extract_part_from_piped_string(health_reason, 1)end-- private-- def reason_is_same(new_health_reason)- health_reason_identifier == self.class.extract_part_from_piped_string(new_health_reason, 0)- endendenddiff --git a/modules/storages/app/services/storages/health_service.rb b/modules/storages/app/services/storages/health_service.rbindex f8e8d84f7b4..0e7b61df578 100644--- a/modules/storages/app/services/storages/health_service.rb+++ b/modules/storages/app/services/storages/health_service.rb@@ -33,42 +33,64 @@ module Storagesenddef healthy- was_unhealthy = @storage.health_unhealthy?- reason = @storage.health_reason+ if @storage.health_status == 'healthy'+ @storage.touch(:health_checked_at)+ else+ reason = @storage.health_reason- @storage.mark_as_healthy+ @storage.update(health_status: 'healthy',+ health_changed_at: Time.now.utc,+ health_checked_at: Time.now.utc,+ health_reason: nil)- admin_users.each do |admin|- ::Storages::StoragesMailer.notify_healthy(admin, @storage, reason).deliver_later if was_unhealthy+ admin_users.each do |admin|+ ::Storages::StoragesMailer.notify_healthy(admin, @storage, reason).deliver_later+ endendenddef unhealthy(reason:)- last_reason = @storage.health_reason- @storage.mark_as_unhealthy(reason:)+ if @storage.health_status == 'unhealthy'+ unless reason_is_same(reason)+ @storage.update(health_changed_at: Time.now.utc,+ health_checked_at: Time.now.utc,+ health_reason: reason)- if @storage.health_reason != last_reason- admin_users.each do |admin|- ::Storages::StoragesMailer.notify_unhealthy(admin, @storage).deliver_later+ notify_unhealthy_admin_usersend- end+ else+ @storage.update(health_status: 'unhealthy',+ health_changed_at: Time.now.utc,+ health_checked_at: Time.now.utc,+ health_reason: reason)- schedule_mail_job(@storage) unless mail_job_exists?+ notify_unhealthy_admin_users+ endendprivate+ def notify_unhealthy_admin_users+ admin_users.each do |admin|+ ::Storages::StoragesMailer.notify_unhealthy(admin, @storage).deliver_later+ end+ end+def admin_usersUser.where(admin: true).where.not(mail: [nil, ''])enddef schedule_mail_job(storage)- ::Storages::HealthStatusMailerJob.schedule(admins: admin_users, storage:)+ ::Storages::HealthStatusMailerJob.schedule(storage:)enddef mail_job_exists?Delayed::Job.where('handler LIKE ?', "%job_class: Storages::HealthStatusMailerJob%").any?end++ def reason_is_same(new_health_reason)+ @storage.health_reason_identifier == Storages::Storage.extract_part_from_piped_string(new_health_reason, 0)+ endendend