Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/jobs/cleanup_submission_entries_job.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
class CleanupSubmissionEntriesJob < ApplicationJob
ENTRIES_BATCH_SIZE = 1000

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def perform(dry_run: false, max_run_time: 5.hours, task_batch_sixe: 100)
def perform(dry_run: false, max_run_time: 5.hours, task_batch_size: 100, entries_batch_size: 500)
start_time = Time.current
total_deleted_entries = 0

Expand All @@ -12,21 +10,23 @@ def perform(dry_run: false, max_run_time: 5.hours, task_batch_sixe: 100)
cleanup_processed: false })
.distinct

tasks_with_unprocessed_submissions.find_in_batches(batch_size: task_batch_sixe) do |tasks_batch|
tasks_with_unprocessed_submissions.find_in_batches(batch_size: task_batch_size) do |tasks_batch|
tasks_batch.each do |task|
active_id = task.active_submission&.id
latest_id = task.latest_submission&.id

failed_submissions = task.submissions
.where(aasm_state: 'validation_failed', cleanup_processed: false)
.where.not(id: active_id)
.where.not(id: latest_id)

next if failed_submissions.empty?

deleted_for_task = 0

failed_submissions.find_each do |submission|
begin
submission.entries.in_batches(of: ENTRIES_BATCH_SIZE) do |entries_batch|
submission.entries.in_batches(of: entries_batch_size) do |entries_batch|
if dry_run
Rollbar.info("Dry run: would delete #{entries_batch.count} entries for Submission ID #{submission.id}.")
else
Expand Down
1 change: 1 addition & 0 deletions app/jobs/data_warehouse_export_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class DataWarehouseExportJob < ApplicationJob
def perform
DataWarehouseExport.generate!
CleanupSubmissionEntriesJob.perform_later
end
end
4 changes: 0 additions & 4 deletions config/sidekiq_schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@ kill_stuck_submissions:
cron: '*/5 * * * *'
class: KillStuckSubmissionsJob
queue: default
cleanup_submission_entries:
cron: '0 1 * * *'
class: CleanupSubmissionEntriesJob
queue: default