diff options
Diffstat (limited to 'app/workers/concerns')
-rw-r--r-- | app/workers/concerns/application_worker.rb | 25 | ||||
-rw-r--r-- | app/workers/concerns/gitlab/github_import/object_importer.rb | 17 | ||||
-rw-r--r-- | app/workers/concerns/waitable_worker.rb | 4 | ||||
-rw-r--r-- | app/workers/concerns/worker_attributes.rb | 3 |
4 files changed, 34 insertions, 15 deletions
diff --git a/app/workers/concerns/application_worker.rb b/app/workers/concerns/application_worker.rb index 3cba1eb31c5..e158ae0c298 100644 --- a/app/workers/concerns/application_worker.rb +++ b/app/workers/concerns/application_worker.rb @@ -47,11 +47,36 @@ module ApplicationWorker end class_methods do + extend ::Gitlab::Utils::Override + def inherited(subclass) subclass.set_queue subclass.after_set_class_attribute { subclass.set_queue } end + override :validate_worker_attributes! + def validate_worker_attributes! + super + + # Since the delayed data_consistency will use sidekiq built in retry mechanism, it is required that this mechanism + # is not disabled. + if retry_disabled? && get_data_consistency == :delayed + raise ArgumentError, "Retry support cannot be disabled if data_consistency is set to :delayed" + end + end + + # Checks if sidekiq retry support is disabled + def retry_disabled? + get_sidekiq_options['retry'] == 0 || get_sidekiq_options['retry'] == false + end + + override :sidekiq_options + def sidekiq_options(opts = {}) + super.tap do + validate_worker_attributes! + end + end + def perform_async(*args) # Worker execution for workers with data_consistency set to :delayed or :sticky # will be delayed to give replication enough time to complete diff --git a/app/workers/concerns/gitlab/github_import/object_importer.rb b/app/workers/concerns/gitlab/github_import/object_importer.rb index 6ebf7c7c263..1eff53cea01 100644 --- a/app/workers/concerns/gitlab/github_import/object_importer.rb +++ b/app/workers/concerns/gitlab/github_import/object_importer.rb @@ -36,14 +36,15 @@ module Gitlab importer_class.new(object, project, client).execute - counter.increment + Gitlab::GithubImport::ObjectCounter.increment(project, object_type, :imported) + info(project.id, message: 'importer finished') rescue StandardError => e error(project.id, e, hash) end - def counter - @counter ||= Gitlab::Metrics.counter(counter_name, counter_description) + def object_type + raise NotImplementedError end # Returns the representation class to use for the object. This class must @@ -57,16 +58,6 @@ module Gitlab raise NotImplementedError end - # Returns the name (as a Symbol) of the Prometheus counter. - def counter_name - raise NotImplementedError - end - - # Returns the description (as a String) of the Prometheus counter. - def counter_description - raise NotImplementedError - end - private attr_accessor :github_id diff --git a/app/workers/concerns/waitable_worker.rb b/app/workers/concerns/waitable_worker.rb index e62bd8d9885..f8b945b8892 100644 --- a/app/workers/concerns/waitable_worker.rb +++ b/app/workers/concerns/waitable_worker.rb @@ -32,7 +32,9 @@ module WaitableWorker failed = [] args_list.each do |args| - new.perform(*args) + worker = new + Gitlab::AppJsonLogger.info(worker.structured_payload(message: 'running inline')) + worker.perform(*args) rescue StandardError failed << args end diff --git a/app/workers/concerns/worker_attributes.rb b/app/workers/concerns/worker_attributes.rb index 096be808787..806fce38636 100644 --- a/app/workers/concerns/worker_attributes.rb +++ b/app/workers/concerns/worker_attributes.rb @@ -12,6 +12,7 @@ module WorkerAttributes VALID_URGENCIES = [:high, :low, :throttled].freeze VALID_DATA_CONSISTENCIES = [:always, :sticky, :delayed].freeze + DEFAULT_DATA_CONSISTENCY = :always NAMESPACE_WEIGHTS = { auto_devops: 2, @@ -110,7 +111,7 @@ module WorkerAttributes end def get_data_consistency - class_attributes[:data_consistency] || :always + class_attributes[:data_consistency] || DEFAULT_DATA_CONSISTENCY end def get_data_consistency_feature_flag_enabled? |