-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework gbif cleanup #1220
Rework gbif cleanup #1220
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -880,6 +880,41 @@ def self.loop_through_events(options) | |
Rails.logger.info("#{label}: task completed") | ||
end | ||
|
||
def self.loop_through_gbif_events(options) | ||
size = (options[:size] || 1_000).to_i | ||
cursor = options[:cursor] || [] | ||
filter = options[:filter] || {} | ||
label = options[:label] || "" | ||
job_name = options[:job_name] || "" | ||
query = options[:query].presence | ||
delete_count = 0 | ||
max_delete_count = options[:max_delete_count] | ||
|
||
response = Event.query(query, filter.merge(page: { size: 1, cursor: [] })) | ||
|
||
if response.size.positive? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should verify |
||
while response.size.positive? && delete_count < max_delete_count | ||
response = Event.query(query, filter.merge(page: { size: size, cursor: cursor })) | ||
|
||
break unless response.size.positive? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can make little readable by checking it like this |
||
|
||
Rails.logger.info("#{label}: #{response.size} events starting with _id #{response.results.to_a.first[:_id]}") | ||
|
||
cursor = response.results.to_a.last[:sort] | ||
|
||
Rails.logger.info "#{label}: cursor: #{cursor}" | ||
|
||
ids = response.results.map(&:_id).uniq | ||
|
||
Object.const_get(job_name).perform_later(ids, options) | ||
|
||
delete_count += response.size | ||
end | ||
end | ||
|
||
Rails.logger.info("#{label}: task completed") | ||
end | ||
|
||
def metric_type | ||
if /(requests|investigations)/.match?(relation_type_id.to_s) | ||
arr = relation_type_id.split("-", 4) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we delete the events using raw query, we are skipping the
after_commit on: [:destroy]
callback.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ashwinisukale yes this is by design as I will be using the bulk api to delete the documents in the events index.