debian-mirror-gitlab/app/services/ci/cancel_user_pipelines_service.rb

19 lines
626 B
Ruby
Raw Normal View History

2019-09-30 23:59:55 +05:30
# 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)
2021-02-11 23:33:58 +05:30
# TODO: fix N+1 queries https://gitlab.com/gitlab-org/gitlab/-/issues/300685
2019-09-30 23:59:55 +05:30
user.pipelines.cancelable.find_each(&:cancel_running)
2020-11-24 15:15:51 +05:30
ServiceResponse.success(message: 'Pipeline canceled')
rescue ActiveRecord::StaleObjectError
ServiceResponse.error(message: 'Error canceling pipeline')
2019-09-30 23:59:55 +05:30
end
# rubocop: enable CodeReuse/ActiveRecord
end
end