diff --git a/app/jobs/delete_gbif_events_job.rb b/app/jobs/delete_gbif_events_job.rb index 25c5bad33..1c7777a84 100644 --- a/app/jobs/delete_gbif_events_job.rb +++ b/app/jobs/delete_gbif_events_job.rb @@ -13,14 +13,13 @@ def perform(ids, options = {}) end # delete event records from mysql - result = Events.where(id: ids).delete_all - Rails.logger.info("#{label}: #{result} event records deleted") + sql = ActiveRecord::Base.sanitize_sql_array(["DELETE FROM events WHERE id IN (?)", ids]) + ActiveRecord::Base.connection.execute(sql) # delete event documents from elasticsearch bulk_payload = ids.map { |id| { delete: { _index: index, _id: id } } } - response = Event.__elasticsearch__.client.bulk(body: bulk_payload) - Rails.logger.info("#{label}: #{response}") + Event.__elasticsearch__.client.bulk(body: bulk_payload) rescue => err - Rails.logger.error("#{label}: #{are.message}") + Rails.logger.error("#{label}: #{err.message}") end end diff --git a/app/models/event.rb b/app/models/event.rb index 4fec93971..a8cae10b6 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -904,9 +904,7 @@ def self.loop_through_gbif_events(options) ids = response.results.map(&:_id).uniq - DeleteGbifEventsJob.perform_later(ids, options) - - # Object.const_get(job_name).perform_later(ids, options) + Object.const_get(job_name).perform_later(ids, options) end end diff --git a/lib/tasks/event.rake b/lib/tasks/event.rake index d20925ea1..dd459ca21 100644 --- a/lib/tasks/event.rake +++ b/lib/tasks/event.rake @@ -88,12 +88,11 @@ namespace :gbif_events do desc "delete gbif events" task delete_gbif_events: :environment do options = { - size: 5, + 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\")", - query: "+relation_type_id:is-authored-by", + 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_event_cleanup_#{Time.now.utc.strftime("%d%m%Y%H%M%S")}", job_name: "DeleteGbifEventsJob" }