From 16a320c5aa034e0ab855255248958f73967f6163 Mon Sep 17 00:00:00 2001 From: Wendel Fabian Chinsamy Date: Tue, 23 Jul 2024 13:55:14 +0200 Subject: [PATCH] change orphan delete implementation --- app/models/event.rb | 3 --- lib/tasks/event.rake | 12 ++++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/models/event.rb b/app/models/event.rb index 41b2f2cc0..b8fe8745c 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -854,7 +854,6 @@ def self.loop_through_events(options) label = options[:label] || "" job_name = options[:job_name] || "" query = options[:query].presence - delete_count = 0 response = Event.query(query, filter.merge(page: { size: 1, cursor: [] })) @@ -874,12 +873,10 @@ def self.loop_through_events(options) ids.each do |id| Object.const_get(job_name).perform_later(id, options) - delete_count += 1 end end end - Rails.logger.info("#{label}: #{delete_count} jobs queued") Rails.logger.info("#{label}: task completed") end diff --git a/lib/tasks/event.rake b/lib/tasks/event.rake index 9146b3b95..8a5850413 100644 --- a/lib/tasks/event.rake +++ b/lib/tasks/event.rake @@ -102,9 +102,17 @@ namespace :gbif_events do desc "delete orphaned gbif_events" task delete_orphaned_gbif_events: :environment do - query = "+subj.registrantId:datacite.gbif.gbif +relation_type_id:references -source_doi:(\"10.15468/QJGWBA\" OR \"10.35035/GDWQ-3V93\" OR \"10.15469/3XSWXB\" OR \"10.15469/UBP6QO\" OR \"10.35000/TEDB-QD70\" OR \"10.15469/2YMQOZ\")" + options = { + size: 1000, + from_id: (ENV["FROM_ID"] || Event.minimum(:id)).to_i, + until_id: (ENV["UNTIL_ID"] || Event.maximum(:id)).to_i, + filter: {}, + query: "+subj.registrantId:datacite.gbif.gbif +relation_type_id:references -source_doi:(\"10.15468/QJGWBA\" OR \"10.35035/GDWQ-3V93\" OR \"10.15469/3XSWXB\" OR \"10.15469/UBP6QO\" OR \"10.35000/TEDB-QD70\" OR \"10.15469/2YMQOZ\")", + label: "gbif_orphaned_gbif_events_job_#{Time.now.utc.strftime("%d%m%Y%H%M%S")}", + job_name: "DeleteOrphanedGbifEventsJob" + } - DeleteOrphanedGbifEventsJob.perform_later(ENV["INDEX"], query) + Event.loop_through_events(options) end end