debian-mirror-gitlab/app/services/events/destroy_service.rb
2022-03-02 08:16:31 +05:30

30 lines
559 B
Ruby

# frozen_string_literal: true
module Events
class DestroyService
BATCH_SIZE = 50
def initialize(project)
@project = project
end
def execute
loop do
count = delete_events_in_batches
break if count < BATCH_SIZE
end
ServiceResponse.success(message: 'Events were deleted.')
rescue StandardError => e
ServiceResponse.error(message: e.message)
end
private
attr_reader :project
def delete_events_in_batches
project.events.limit(BATCH_SIZE).delete_all
end
end
end