Skip to content

Commit baf2494

Browse files
Add batch processing logic to the crossref rake task
1 parent 260925a commit baf2494

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/tasks/event.rake

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ namespace :event do
1515
events = Event
1616
.where(source_id: ["crossref", "datacite-crossref"])
1717
.where(created_at: start_date...end_date)
18+
.order(:id)
1819

1920
puts("Number of events: #{events.count}")
2021

21-
Parallel.each(events, in_threads: 20) do |event|
22-
SqsUtilities.send_events_other_doi_job_message({
23-
subj_id: event.subj_id,
24-
obj_id: event.obj_id,
25-
})
22+
events.in_batches(of: 10_000) do |batch|
23+
batch_events = batch.select(:id, :subj_id, :obj_id).to_a
24+
25+
Parallel.each(batch_events, in_threads: 20) do |batch_event|
26+
SqsUtilities.send_events_other_doi_job_message({
27+
subj_id: batch_event.subj_id,
28+
obj_id: batch_event.obj_id,
29+
})
30+
end
2631
end
2732
end
2833
end

0 commit comments

Comments
 (0)