bf9ab0f33d
The intended flow is: Soft-delete group (sync) -> Delete group projects (async) -> Hard-delete group (async) The soft-delete was run in a transaction, which was committed only after the async job (for hard-deletion) was kicked off. There was a race condition here - the soft-delete transaction could complete _after_ the hard delete completed, leaving a soft-deleted record in the database. This commit removes this race condition. There is no need to run the soft-delete in a transaction. The soft-delete completes before the async job is kicked off.
25 lines
795 B
Ruby
25 lines
795 B
Ruby
class DestroyGroupService
|
|
attr_accessor :group, :current_user
|
|
|
|
def initialize(group, user)
|
|
@group, @current_user = group, user
|
|
end
|
|
|
|
def async_execute
|
|
# Soft delete via paranoia gem
|
|
group.destroy
|
|
job_id = GroupDestroyWorker.perform_async(group.id, current_user.id)
|
|
Rails.logger.info("User #{current_user.id} scheduled a deletion of group ID #{group.id} with job ID #{job_id}")
|
|
end
|
|
|
|
def execute
|
|
group.projects.each do |project|
|
|
# Execute the destruction of the models immediately to ensure atomic cleanup.
|
|
# Skip repository removal because we remove directory with namespace
|
|
# that contain all these repositories
|
|
::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
|
|
end
|
|
|
|
group.really_destroy!
|
|
end
|
|
end
|