Commit 3f826d39 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'bvl-add-related-class-to-reactive-caching-worker' into 'master'

Add related class to reactive caching worker

See merge request gitlab-org/gitlab!27687
parents bc1f926e ca03d5cc
......@@ -301,7 +301,7 @@ gem 'sentry-raven', '~> 2.9'
gem 'premailer-rails', '~> 1.10.3'
# LabKit: Tracing and Correlation
gem 'gitlab-labkit', '0.11.0'
gem 'gitlab-labkit', '0.12.0'
# I18n
gem 'ruby_parser', '~> 3.8', require: false
......
......@@ -380,7 +380,7 @@ GEM
rake (> 10, < 14)
ruby-statistics (>= 2.1)
thor (>= 0.19, < 2)
gitlab-labkit (0.11.0)
gitlab-labkit (0.12.0)
actionpack (>= 5.0.0, < 6.1.0)
activesupport (>= 5.0.0, < 6.1.0)
grpc (~> 1.19)
......@@ -1232,7 +1232,7 @@ DEPENDENCIES
github-markup (~> 1.7.0)
gitlab-chronic (~> 0.10.5)
gitlab-derailed_benchmarks
gitlab-labkit (= 0.11.0)
gitlab-labkit (= 0.12.0)
gitlab-license (~> 1.0)
gitlab-mail_room (~> 0.0.3)
gitlab-markup (~> 1.7.0)
......
......@@ -13,6 +13,11 @@ class ReactiveCachingWorker # rubocop:disable Scalability/IdempotentWorker
urgency :high
worker_resource_boundary :cpu
def self.context_for_arguments(arguments)
class_name, *_other_args = arguments
Gitlab::ApplicationContext.new(related_class: class_name)
end
def perform(class_name, id, *args)
klass = begin
class_name.constantize
......
......@@ -62,6 +62,11 @@ input AdminSidekiqQueuesDeleteJobsInput {
"""
queueName: String!
"""
Delete jobs matching related_class in the context metadata
"""
relatedClass: String
"""
Delete jobs matching root_namespace in the context metadata
"""
......
......@@ -181,6 +181,16 @@
},
"defaultValue": null
},
{
"name": "relatedClass",
"description": "Delete jobs matching related_class in the context metadata",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "queueName",
"description": "The name of the queue to delete jobs from",
......
......@@ -5,13 +5,14 @@ module Gitlab
class ApplicationContext
include Gitlab::Utils::LazyAttributes
Attribute = Struct.new(:name, :type, :evaluation)
Attribute = Struct.new(:name, :type)
APPLICATION_ATTRIBUTES = [
Attribute.new(:project, Project),
Attribute.new(:namespace, Namespace),
Attribute.new(:user, User),
Attribute.new(:caller_id, String)
Attribute.new(:caller_id, String),
Attribute.new(:related_class, String)
].freeze
def self.with_context(args, &block)
......@@ -39,6 +40,7 @@ module Gitlab
hash[:project] = -> { project_path } if set_values.include?(:project)
hash[:root_namespace] = -> { root_namespace_path } if include_namespace?
hash[:caller_id] = caller_id if set_values.include?(:caller_id)
hash[:related_class] = related_class if set_values.include?(:related_class)
end
end
......
......@@ -28,4 +28,14 @@ describe ReactiveCachingWorker do
end
end
end
describe 'worker context' do
it 'sets the related class on the job' do
described_class.perform_async('Environment', 1, 'other', 'argument')
scheduled_job = described_class.jobs.first
expect(scheduled_job).to include('meta.related_class' => 'Environment')
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment