diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 5a08339e3..52b81f169 100644 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -36,6 +36,11 @@ module Api def health User.new && Team.new && Project.new User.first if params[:db] + if Rails.application.secrets.system_notifications_uri.present? && + Rails.application.secrets.system_notifications_channel.present? && + !Notifications::SyncSystemNotificationsService.available? + return render plain: 'SYSTEM NOTIFICATIONS SERVICE CHECK FAILED', status: :error + end render plain: 'RUNNING' end diff --git a/app/services/notifications/sync_system_notifications_service.rb b/app/services/notifications/sync_system_notifications_service.rb index af3a925a9..789ec6a29 100644 --- a/app/services/notifications/sync_system_notifications_service.rb +++ b/app/services/notifications/sync_system_notifications_service.rb @@ -24,6 +24,14 @@ module Notifications @errors.none? end + def self.available? + channel = Rails.application.secrets.system_notifications_channel + query = { query: { last_sync_timestamp: Time.now.to_i, channels_slug: channel }, + headers: { 'accept': 'application/vnd.system-notifications.1+json' } } + response = get('/api/system_notifications', query) + response.code < Rack::Utils::SYMBOL_TO_STATUS_CODE[:bad_request] + end + private def call_api