Class: Mutations::Admin::SidekiqQueues::DeleteJobs

Inherits:
BaseMutation
  • Object
show all
Defined in:
app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb

Constant Summary collapse

ADMIN_MESSAGE =
'You must be an admin to use this mutation'

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Instance Method Summary collapse

Methods inherited from BaseMutation

#api_user?, authorization, authorized?, authorizes_object?, #current_user, #errors_on_object, #load_application_object, #read_only?, #unauthorized_object

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #find_object, #raise_resource_not_available_error!

Instance Method Details

#ready?(**args) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb', line 33

def ready?(**args)
  unless current_user&.admin?
    raise Gitlab::Graphql::Errors::ResourceNotAvailable, ADMIN_MESSAGE
  end

  super
end

#resolve(queue_name:, **args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb', line 41

def resolve(queue_name:, **args)
  {
    result: Gitlab::SidekiqQueue.new(queue_name).drop_jobs!(args, timeout: 30),
    errors: []
  }
rescue Gitlab::SidekiqQueue::NoMetadataError
  {
    result: nil,
    errors: ['No metadata provided']
  }
rescue Gitlab::SidekiqQueue::InvalidQueueError
  raise Gitlab::Graphql::Errors::ResourceNotAvailable, "Queue #{queue_name} not found"
end