2019-09-13 02:40:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Ci
|
|
|
|
class CancelUserPipelinesService
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
# This is a bug with CodeReuse/ActiveRecord cop
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/issues/32332
|
|
|
|
def execute(user)
|
|
|
|
user.pipelines.cancelable.find_each(&:cancel_running)
|
2020-08-27 11:10:21 -04:00
|
|
|
|
|
|
|
ServiceResponse.success(message: 'Pipeline canceled')
|
|
|
|
rescue ActiveRecord::StaleObjectError
|
|
|
|
ServiceResponse.error(message: 'Error canceling pipeline')
|
2019-09-13 02:40:00 -04:00
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
end
|
|
|
|
end
|