Commit 574fb917 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Add related_class ReactiveCachingWorker logging

This adds the `meta.related_class` keyword to the job hash. This will
make it easier to determine what different kinds of work this worker
is doing.
parent 31760a83
...@@ -13,6 +13,11 @@ class ReactiveCachingWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -13,6 +13,11 @@ class ReactiveCachingWorker # rubocop:disable Scalability/IdempotentWorker
urgency :high urgency :high
worker_resource_boundary :cpu 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) def perform(class_name, id, *args)
klass = begin klass = begin
class_name.constantize class_name.constantize
......
...@@ -62,6 +62,11 @@ input AdminSidekiqQueuesDeleteJobsInput { ...@@ -62,6 +62,11 @@ input AdminSidekiqQueuesDeleteJobsInput {
""" """
queueName: String! queueName: String!
"""
Delete jobs matching related_class in the context metadata
"""
relatedClass: String
""" """
Delete jobs matching root_namespace in the context metadata Delete jobs matching root_namespace in the context metadata
""" """
......
...@@ -181,6 +181,16 @@ ...@@ -181,6 +181,16 @@
}, },
"defaultValue": null "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", "name": "queueName",
"description": "The name of the queue to delete jobs from", "description": "The name of the queue to delete jobs from",
......
...@@ -11,7 +11,8 @@ module Gitlab ...@@ -11,7 +11,8 @@ module Gitlab
Attribute.new(:project, Project), Attribute.new(:project, Project),
Attribute.new(:namespace, Namespace), Attribute.new(:namespace, Namespace),
Attribute.new(:user, User), Attribute.new(:user, User),
Attribute.new(:caller_id, String) Attribute.new(:caller_id, String),
Attribute.new(:related_class, String)
].freeze ].freeze
def self.with_context(args, &block) def self.with_context(args, &block)
...@@ -39,6 +40,7 @@ module Gitlab ...@@ -39,6 +40,7 @@ module Gitlab
hash[:project] = -> { project_path } if set_values.include?(:project) hash[:project] = -> { project_path } if set_values.include?(:project)
hash[:root_namespace] = -> { root_namespace_path } if include_namespace? hash[:root_namespace] = -> { root_namespace_path } if include_namespace?
hash[:caller_id] = caller_id if set_values.include?(:caller_id) hash[:caller_id] = caller_id if set_values.include?(:caller_id)
hash[:related_class] = related_class if set_values.include?(:related_class)
end end
end end
......
...@@ -28,4 +28,14 @@ describe ReactiveCachingWorker do ...@@ -28,4 +28,14 @@ describe ReactiveCachingWorker do
end end
end 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 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