This repository has been archived by the owner on Mar 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2913: TASK: update objects in CITI with recently updated preferred re…
…presentation imaging_uid's (#476) https://cits.artic.edu/issues/2913 * 2913: TASK: update objects in CITI with recently updated preferred representation imaging_uid's * adds a task to count just so we know how many notifications will be sent to citi if we were to run the main task * benchmarks the tasks * use solr joins and fq's! (#477)
- Loading branch information
1 parent
3ce375b
commit c787e05
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
require 'benchmark' | ||
|
||
class Rake::Task | ||
def execute_with_benchmark(*args) | ||
bm = Benchmark.measure { execute_without_benchmark(*args) } | ||
puts " #{name} --> #{bm}" | ||
end | ||
|
||
alias execute_without_benchmark execute | ||
alias execute execute_with_benchmark | ||
end | ||
|
||
namespace :citi_notifications do | ||
desc "Counts the number assets that have been modified after a certain date 'YYYY-MM-DD', are preferred reps, and have an imaging uid" | ||
task :count_assets_to_update, [:modified_after] => :environment do |_t, args| | ||
date_passed_in = args[:modified_after] | ||
new_solr_date = date_passed_in + "T00:00:00Z" | ||
|
||
query = "{!join from=preferred_representation_ssim to=id}preferred_representation_ssim:*" | ||
fq = [] | ||
fq << "has_model_ssim:GenericWork" | ||
fq << "system_modified_dtsi:[#{new_solr_date} TO NOW]" | ||
|
||
asset_ids = ActiveFedora::SolrService.query( query, { fq: fq, rows: 100_000 } ).map(&:id) | ||
|
||
puts "Found #{asset_ids.count} preferred rep assets in Solr, edited after #{args[:modified_after]}." | ||
end | ||
|
||
desc "Send image_uid notifications to CITI for assets that have been modified since a certain date 'YYYY-MM-DD'" | ||
task :update_imaging_uids, [:modified_after] => :environment do |_t, args| | ||
date_passed_in = args[:modified_after] | ||
new_solr_date = date_passed_in + "T00:00:00Z" | ||
|
||
query = "{!join from=preferred_representation_ssim to=id}preferred_representation_ssim:*" | ||
fq = [] | ||
fq << "has_model_ssim:GenericWork" | ||
fq << "system_modified_dtsi:[#{new_solr_date} TO NOW]" | ||
|
||
asset_ids = ActiveFedora::SolrService.query( query, { fq: fq, rows: 100_000 } ).map(&:id) | ||
|
||
asset_ids.each do |asset_id| | ||
generic_work_object = GenericWork.find(asset_id) | ||
intermediate_file_set = generic_work_object.intermediate_file_set.first | ||
puts "Enqueueing CitiNotificationJob for #{generic_work_object.try(:title)} last modified #{generic_work_object.date_modified}" | ||
CitiNotificationJob.perform_later(intermediate_file_set, nil, true) | ||
end | ||
|
||
puts "Task completed with a total of #{asset_ids.count} preferred rep assets, edited after #{args[:modified_after]}." | ||
end | ||
end | ||
|
||
# GenericWork.where("system_modified_dtsi:[NOW/DAY TO NOW]") | ||
# https://lucene.apache.org/solr/guide/7_3/working-with-dates.html | ||
# GenericWork.where("system_modified_dtsi:[2018-02-28 TO NOW]") | ||
# 2018-02-28T00:00:00Z |