2021-12-15 16:11:32 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Events
|
|
|
|
class DestroyService
|
2021-12-23 22:13:52 -05:00
|
|
|
BATCH_SIZE = 50
|
|
|
|
|
2021-12-15 16:11:32 -05:00
|
|
|
def initialize(project)
|
|
|
|
@project = project
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2021-12-23 22:13:52 -05:00
|
|
|
loop do
|
|
|
|
count = delete_events_in_batches
|
|
|
|
break if count < BATCH_SIZE
|
|
|
|
end
|
2021-12-15 16:11:32 -05:00
|
|
|
|
|
|
|
ServiceResponse.success(message: 'Events were deleted.')
|
2021-12-23 22:13:52 -05:00
|
|
|
rescue StandardError => e
|
|
|
|
ServiceResponse.error(message: e.message)
|
2021-12-15 16:11:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :project
|
2021-12-23 22:13:52 -05:00
|
|
|
|
|
|
|
def delete_events_in_batches
|
|
|
|
project.events.limit(BATCH_SIZE).delete_all
|
|
|
|
end
|
2021-12-15 16:11:32 -05:00
|
|
|
end
|
|
|
|
end
|