Skip to content

Commit

Permalink
change orphan delete implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
wendelfabianchinsamy committed Jul 23, 2024
1 parent ee9c2df commit 16a320c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 0 additions & 3 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] }))

Expand All @@ -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

Expand Down
12 changes: 10 additions & 2 deletions lib/tasks/event.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 16a320c

Please sign in to comment.