debian-mirror-gitlab/app/graphql/mutations/ci/runner/bulk_delete.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.6 KiB
Ruby
Raw Normal View History

2022-08-27 11:52:29 +05:30
# frozen_string_literal: true
module Mutations
module Ci
module Runner
class BulkDelete < BaseMutation
graphql_name 'BulkRunnerDelete'
RunnerID = ::Types::GlobalIDType[::Ci::Runner]
argument :ids, [RunnerID],
required: false,
description: 'IDs of the runners to delete.'
field :deleted_count,
::GraphQL::Types::Int,
null: true,
description: 'Number of records effectively deleted. ' \
'Only present if operation was performed synchronously.'
field :deleted_ids,
[RunnerID],
null: true,
description: 'IDs of records effectively deleted. ' \
'Only present if operation was performed synchronously.'
def resolve(**runner_attrs)
if ids = runner_attrs[:ids]
2023-01-13 00:05:48 +05:30
runner_ids = model_ids_of(ids)
runners = find_all_runners_by_ids(runner_ids)
2022-08-27 11:52:29 +05:30
2023-01-13 00:05:48 +05:30
result = ::Ci::Runners::BulkDeleteRunnersService.new(runners: runners, current_user: current_user).execute
result.payload.slice(:deleted_count, :deleted_ids, :errors)
2022-08-27 11:52:29 +05:30
else
{ errors: [] }
end
end
private
2023-01-13 00:05:48 +05:30
def model_ids_of(global_ids)
global_ids.filter_map { |gid| gid.model_id.to_i }
2022-08-27 11:52:29 +05:30
end
def find_all_runners_by_ids(ids)
return ::Ci::Runner.none if ids.blank?
2023-01-13 00:05:48 +05:30
limit = ::Ci::Runners::BulkDeleteRunnersService::RUNNER_LIMIT
::Ci::Runner.id_in(ids).limit(limit + 1)
2022-08-27 11:52:29 +05:30
end
end
end
end
end