debian-mirror-gitlab/app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb

53 lines
1.5 KiB
Ruby
Raw Normal View History

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'
Labkit::Context::KNOWN_KEYS.each do |key|
argument key,
GraphQL::STRING_TYPE,
required: false,
description: "Delete jobs matching #{key} in the context metadata"
end
argument :queue_name,
GraphQL::STRING_TYPE,
required: true,
description: 'The name of the queue to delete jobs from'
field :result,
Types::Admin::SidekiqQueues::DeleteJobsResponseType,
null: true,
description: 'Information about the status of the deletion request'
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