33require 'text'
44require 'httparty'
55
6+ # Error handling to log in more detail and also send an email
7+ def handle_error ( subj :, err :)
8+ puts ''
9+ puts err . message
10+ puts err . backtrace
11+
12+ UserMailer . rake_failure ( subj :, err :) . deliver_now
13+
14+ puts ''
15+ end
16+
617namespace :housekeeping do
718 desc 'Clear the cache'
819 task clear_cache : :environment do
@@ -13,25 +24,53 @@ namespace :housekeeping do
1324 task monthly_maintenance : :environment do
1425 p '----------------------------------'
1526 p 'Step 1 of 7 - Purging old OAuth tokens and grants'
16- Rake ::Task [ 'housekeeping:cleanup_oauth' ] . execute
27+ begin
28+ Rake ::Task [ 'housekeeping:cleanup_oauth' ] . execute
29+ rescue StandardError => e
30+ handle_error ( subj : 'Purge old OAuth artifacts' , err : e )
31+ end
1732 p '----------------------------------'
1833 p 'Step 2 of 7 - Purging old External API tokens'
19- Rake ::Task [ 'housekeeping:cleanup_external_api_access_tokens' ] . execute
34+ begin
35+ Rake ::Task [ 'housekeeping:cleanup_external_api_access_tokens' ] . execute
36+ rescue StandardError => e
37+ handle_error ( subj : 'Purge old External API tokens' , err : e )
38+ end
2039 p '----------------------------------'
2140 p 'Step 3 of 7 - Generating monthly usage statistics'
22- Rake ::Task [ 'stat:build_last_month_parallel' ] . execute
41+ begin
42+ Rake ::Task [ 'stat:build_last_month_parallel' ] . execute
43+ rescue StandardError => e
44+ handle_error ( subj : 'Generating monthly usage stats' , err : e )
45+ end
2346 p '----------------------------------'
2447 p 'Step 4 of 7 - Fetching latest data from RDA Metadata standard catalog'
25- Rake ::Task [ 'external_api:load_rdamsc_standards' ] . execute
48+ begin
49+ Rake ::Task [ 'external_api:load_rdamsc_standards' ] . execute
50+ rescue StandardError => e
51+ handle_error ( subj : 'Fetching latest Metadata Standards from RDA' , err : e )
52+ end
2653 p '----------------------------------'
2754 p 'Step 5 of 7 - Fetching latest data from SPX license database'
28- Rake ::Task [ 'external_api:load_spdx_licenses' ] . execute
55+ begin
56+ Rake ::Task [ 'external_api:load_spdx_licenses' ] . execute
57+ rescue StandardError => e
58+ handle_error ( subj : 'Fetching latest Licenses from SPDX' , err : e )
59+ end
2960 p '----------------------------------'
3061 p 'Step 6 of 7 - Fetching latest data from the re3data repository'
31- Rake ::Task [ 'external_api:load_re3data_repos' ] . execute
62+ begin
63+ Rake ::Task [ 'external_api:load_re3data_repos' ] . execute
64+ rescue StandardError => e
65+ handle_error ( subj : 'Fetching latest Repositories from re3data' , err : e )
66+ end
3267 p '----------------------------------'
3368 p 'Step 7 of 7 - Fetching latest data from the ROR API'
34- Rake ::Task [ 'external_api:sync_registry_orgs' ] . execute
69+ begin
70+ Rake ::Task [ 'external_api:sync_registry_orgs' ] . execute
71+ rescue StandardError => e
72+ handle_error ( subj : 'Fetching latest Orgs from ROR' , err : e )
73+ end
3574 end
3675
3776 desc 'Sync DMP metadata with the DMP ID minting authority'
@@ -79,7 +118,6 @@ namespace :housekeeping do
79118 task cleanup_oauth : :environment do
80119 # Removing expired Access Tokens and Grants to help prune the DB
81120 # - Note that expiration values are stored in seconds!
82-
83121 Doorkeeper ::AccessGrant . all . each do |grant |
84122 expiry = grant . created_at + grant . expires_in . seconds
85123 grant . destroy if Time . zone . now >= expiry
0 commit comments