debian-mirror-gitlab/app/services/events/destroy_service.rb

31 lines
559 B
Ruby
Raw Normal View History

2022-01-26 12:08:38 +05:30
# frozen_string_literal: true
module Events
class DestroyService
2022-03-02 08:16:31 +05:30
BATCH_SIZE = 50
2022-01-26 12:08:38 +05:30
def initialize(project)
@project = project
end
def execute
2022-03-02 08:16:31 +05:30
loop do
count = delete_events_in_batches
break if count < BATCH_SIZE
end
2022-01-26 12:08:38 +05:30
ServiceResponse.success(message: 'Events were deleted.')
2022-03-02 08:16:31 +05:30
rescue StandardError => e
ServiceResponse.error(message: e.message)
2022-01-26 12:08:38 +05:30
end
private
attr_reader :project
2022-03-02 08:16:31 +05:30
def delete_events_in_batches
project.events.limit(BATCH_SIZE).delete_all
end
2022-01-26 12:08:38 +05:30
end
end