2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Admin
|
|
|
|
module SidekiqQueues
|
|
|
|
class DeleteJobs < BaseMutation
|
|
|
|
graphql_name 'AdminSidekiqQueuesDeleteJobs'
|
|
|
|
|
|
|
|
ADMIN_MESSAGE = 'You must be an admin to use this mutation'
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
::Gitlab::ApplicationContext.known_keys.each do |key|
|
2020-04-08 14:13:33 +05:30
|
|
|
argument key,
|
2021-10-27 15:23:28 +05:30
|
|
|
GraphQL::Types::String,
|
2020-04-08 14:13:33 +05:30
|
|
|
required: false,
|
2021-11-11 11:23:49 +05:30
|
|
|
description: "Delete jobs matching #{key} in the context metadata."
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
argument ::Gitlab::SidekiqQueue::WORKER_KEY,
|
|
|
|
GraphQL::Types::String,
|
|
|
|
required: false,
|
|
|
|
description: 'Delete jobs with the given worker class.'
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
argument :queue_name,
|
2021-10-27 15:23:28 +05:30
|
|
|
GraphQL::Types::String,
|
2020-04-08 14:13:33 +05:30
|
|
|
required: true,
|
2021-10-27 15:23:28 +05:30
|
|
|
description: 'Name of the queue to delete jobs from.'
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
field :result,
|
|
|
|
Types::Admin::SidekiqQueues::DeleteJobsResponseType,
|
|
|
|
null: true,
|
2021-03-08 18:12:59 +05:30
|
|
|
description: 'Information about the status of the deletion request.'
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
def ready?(**args)
|
|
|
|
unless current_user&.admin?
|
|
|
|
raise Gitlab::Graphql::Errors::ResourceNotAvailable, ADMIN_MESSAGE
|
|
|
|
end
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
def resolve(queue_name:, **args)
|
2020-04-08 14:13:33 +05:30
|
|
|
{
|
2021-01-29 00:20:46 +05:30
|
|
|
result: Gitlab::SidekiqQueue.new(queue_name).drop_jobs!(args, timeout: 30),
|
2020-04-08 14:13:33 +05:30
|
|
|
errors: []
|
|
|
|
}
|
|
|
|
rescue Gitlab::SidekiqQueue::NoMetadataError
|
|
|
|
{
|
|
|
|
result: nil,
|
|
|
|
errors: ['No metadata provided']
|
|
|
|
}
|
|
|
|
rescue Gitlab::SidekiqQueue::InvalidQueueError
|
2021-01-29 00:20:46 +05:30
|
|
|
raise Gitlab::Graphql::Errors::ResourceNotAvailable, "Queue #{queue_name} not found"
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|