Skip to content

Commit

Permalink
support slack reporting in dois not indexed check. #690
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 5, 2021
1 parent c4bece9 commit 712bab3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
10 changes: 5 additions & 5 deletions app/controllers/exports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions app/jobs/import_dois_not_indexed_job.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 16 additions & 2 deletions app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/models/concerns/mailable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 712bab3

Please sign in to comment.