From 712bab3b5343fb2209b59639dedc5353a7a56574 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Tue, 5 Jan 2021 14:54:09 +0100 Subject: [PATCH] support slack reporting in dois not indexed check. #690 --- app/controllers/exports_controller.rb | 10 +++++----- app/jobs/import_dois_not_indexed_job.rb | 9 +++++++++ app/models/client.rb | 18 ++++++++++++++++-- app/models/concerns/mailable.rb | 1 - app/models/user.rb | 2 +- config/routes.rb | 2 +- 6 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 app/jobs/import_dois_not_indexed_job.rb diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index 223338c80..889887fb7 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -488,11 +488,11 @@ def repositories status: :bad_request end - def check_indexed_dois - csv = Client.export_doi_counts - filename = "repositories-not-fully-indexed-#{Date.today}.csv" - - send_data csv, filename: filename + def import_dois_not_indexed + ImportDoisNotIndexJob.perform_later(nil) + render plain: "OK", + status: 202, + content_type: "text/plain" end def export_date(date) diff --git a/app/jobs/import_dois_not_indexed_job.rb b/app/jobs/import_dois_not_indexed_job.rb new file mode 100644 index 000000000..52b1d83cc --- /dev/null +++ b/app/jobs/import_dois_not_indexed_job.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class ImportDoisNotIndexedJob < ApplicationJob + queue_as :lupo_background + + def perform(query, _options = {}) + Client.import_dois_not_indexed(query: query) + end +end diff --git a/app/models/client.rb b/app/models/client.rb index 1a6538910..4646f8197 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -700,8 +700,20 @@ def self.export_doi_counts(query: nil) sum end + title = if Rails.env.stage? + if ENV["ES_PREFIX"].present? + "DataCite Fabrica Stage" + else + "DataCite Fabrica Test" + end + else + "DataCite Fabrica" + end + if rows.blank? - Rails.logger.warn "Found 0 repositories with missing DOIs." + message = "Found 0 repositories with DOIs not indexed." + Rails.logger.warn message + self.send_notification_to_slack(title + ": " + message, level: "good") return nil end @@ -712,7 +724,9 @@ def self.export_doi_counts(query: nil) sum end - Rails.logger.warn "Found #{csv.size - 1} repositories with #{total_missing} missing DOIs." + message = "Found #{csv.size - 1} repositories with #{total_missing} DOIs not indexed." + Rails.logger.warn message + self.send_notification_to_slack(title + ": " + message, level: "warning") csv.join("") end diff --git a/app/models/concerns/mailable.rb b/app/models/concerns/mailable.rb index f93480613..fa663ef8b 100644 --- a/app/models/concerns/mailable.rb +++ b/app/models/concerns/mailable.rb @@ -148,7 +148,6 @@ module ClassMethods SLACK_ICON_URL = "https://github.com/datacite/segugio/blob/master/source/images/fabrica.png" - class NoOpHTTPClient def self.post(_uri, params = {}) Rails.logger.info JSON.parse(params[:payload]) diff --git a/app/models/user.rb b/app/models/user.rb index ada5b456a..f02fd5c3e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,7 +7,7 @@ class User # include helper module for setting password include Passwordable - # include helper module for setting emails via Mailgun API + # include helper module for sending emails via Mailgun API include Mailable # include helper module for caching infrequently changing resources diff --git a/config/routes.rb b/config/routes.rb index 1628297b0..d2f0f3936 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -169,7 +169,7 @@ get "export/repositories", to: "exports#repositories", defaults: { format: :csv } get "export/contacts", to: "exports#contacts", defaults: { format: :csv } - get "export/check-indexed-dois", to: "exports#check_indexed_dois" + get "export/check-indexed-dois", to: "exports#import_dois_not_indexed" resources :heartbeat, only: %i[index]