Skip to content

Commit

Permalink
add a separate gbif loop function
Browse files Browse the repository at this point in the history
  • Loading branch information
wendelfabianchinsamy committed Jul 25, 2024
1 parent 83c7b11 commit 532c4e0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
9 changes: 4 additions & 5 deletions app/jobs/delete_gbif_events_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit 532c4e0

Please sign in to comment.