Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-03 18:08:08 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-03 18:08:08 +0300
commit946771d0b016ae92b15a60bc3290a33b94191ffe (patch)
tree64862c2433989483f5fce45d5539242577a362eb /app/graphql
parentf1e2fca19a90a6992c2020cf8c2159cfb0b61bca (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/graphql')
-rw-r--r--app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb52
-rw-r--r--app/graphql/types/admin/sidekiq_queues/delete_jobs_response_type.rb29
-rw-r--r--app/graphql/types/mutation_type.rb1
3 files changed, 82 insertions, 0 deletions
diff --git a/app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb b/app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb
new file mode 100644
index 00000000000..a3a421f8938
--- /dev/null
+++ b/app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb
@@ -0,0 +1,52 @@
+# 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
+
+ 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
+ end
+ end
+ end
+end
diff --git a/app/graphql/types/admin/sidekiq_queues/delete_jobs_response_type.rb b/app/graphql/types/admin/sidekiq_queues/delete_jobs_response_type.rb
new file mode 100644
index 00000000000..69af9d463bb
--- /dev/null
+++ b/app/graphql/types/admin/sidekiq_queues/delete_jobs_response_type.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module Types
+ module Admin
+ module SidekiqQueues
+ # We can't authorize against the value passed to this because it's
+ # a plain hash.
+ class DeleteJobsResponseType < BaseObject # rubocop:disable Graphql/AuthorizeTypes
+ graphql_name 'DeleteJobsResponse'
+ description 'The response from the AdminSidekiqQueuesDeleteJobs mutation.'
+
+ field :completed,
+ GraphQL::BOOLEAN_TYPE,
+ null: true,
+ description: 'Whether or not the entire queue was processed in time; if not, retrying the same request is safe'
+
+ field :deleted_jobs,
+ GraphQL::INT_TYPE,
+ null: true,
+ description: 'The number of matching jobs deleted'
+
+ field :queue_size,
+ GraphQL::INT_TYPE,
+ null: true,
+ description: 'The queue size after processing'
+ end
+ end
+ end
+end
diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb
index 90e9e1ec0b9..d3c0d9732d2 100644
--- a/app/graphql/types/mutation_type.rb
+++ b/app/graphql/types/mutation_type.rb
@@ -6,6 +6,7 @@ module Types
graphql_name 'Mutation'
+ mount_mutation Mutations::Admin::SidekiqQueues::DeleteJobs
mount_mutation Mutations::AwardEmojis::Add
mount_mutation Mutations::AwardEmojis::Remove
mount_mutation Mutations::AwardEmojis::Toggle