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

Instance Method Summary collapse

Methods inherited from BaseMutation

#api_user?, #current_user, #errors_on_object

Instance Method Details

#ready?(**args) ⇒ Boolean

Returns:

  • (Boolean)

28
29
30
31
32
33
34
# File 'app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb', line 28

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

  super
end

#resolve(args) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb', line 36

def resolve(args)
  {
    result: Gitlab::SidekiqQueue.new(args[: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 #{args[:queue_name]} not found"
end