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-07-20 15:26:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /app/workers/concerns
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'app/workers/concerns')
-rw-r--r--app/workers/concerns/project_export_options.rb25
-rw-r--r--app/workers/concerns/reenqueuer.rb6
-rw-r--r--app/workers/concerns/worker_attributes.rb68
3 files changed, 26 insertions, 73 deletions
diff --git a/app/workers/concerns/project_export_options.rb b/app/workers/concerns/project_export_options.rb
deleted file mode 100644
index e9318c1ba43..00000000000
--- a/app/workers/concerns/project_export_options.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-# frozen_string_literal: true
-
-module ProjectExportOptions
- extend ActiveSupport::Concern
-
- EXPORT_RETRY_COUNT = 3
-
- included do
- sidekiq_options retry: EXPORT_RETRY_COUNT, status_expiration: StuckExportJobsWorker::EXPORT_JOBS_EXPIRATION
-
- # We mark the project export as failed once we have exhausted all retries
- sidekiq_retries_exhausted do |job|
- project = Project.find(job['args'][1])
- # rubocop: disable CodeReuse/ActiveRecord
- job = project.export_jobs.find_by(jid: job["jid"])
- # rubocop: enable CodeReuse/ActiveRecord
-
- if job&.fail_op
- Sidekiq.logger.info "Job #{job['jid']} for project #{project.id} has been set to failed state"
- else
- Sidekiq.logger.error "Failed to set Job #{job['jid']} for project #{project.id} to failed state"
- end
- end
- end
-end
diff --git a/app/workers/concerns/reenqueuer.rb b/app/workers/concerns/reenqueuer.rb
index 5cc13e490d8..bf6f6546c03 100644
--- a/app/workers/concerns/reenqueuer.rb
+++ b/app/workers/concerns/reenqueuer.rb
@@ -60,8 +60,6 @@ module Reenqueuer
5.seconds
end
- # We intend to get rid of sleep:
- # https://gitlab.com/gitlab-org/gitlab/issues/121697
module ReenqueuerSleeper
# The block will run, and then sleep until the minimum duration. Returns the
# block's return value.
@@ -73,7 +71,7 @@ module Reenqueuer
# end
#
def ensure_minimum_duration(minimum_duration)
- start_time = Time.now
+ start_time = Time.current
result = yield
@@ -95,7 +93,7 @@ module Reenqueuer
end
def elapsed_time(start_time)
- Time.now - start_time
+ Time.current - start_time
end
end
end
diff --git a/app/workers/concerns/worker_attributes.rb b/app/workers/concerns/worker_attributes.rb
index b19217b15de..bb6192166b4 100644
--- a/app/workers/concerns/worker_attributes.rb
+++ b/app/workers/concerns/worker_attributes.rb
@@ -2,6 +2,7 @@
module WorkerAttributes
extend ActiveSupport::Concern
+ include Gitlab::ClassAttributes
# Resource boundaries that workers can declare through the
# `resource_boundary` attribute
@@ -30,24 +31,24 @@ module WorkerAttributes
}.stringify_keys.freeze
class_methods do
- def feature_category(value)
+ def feature_category(value, *extras)
raise "Invalid category. Use `feature_category_not_owned!` to mark a worker as not owned" if value == :not_owned
- worker_attributes[:feature_category] = value
+ class_attributes[:feature_category] = value
end
# Special case: mark this work as not associated with a feature category
# this should be used for cross-cutting concerns, such as mailer workers.
def feature_category_not_owned!
- worker_attributes[:feature_category] = :not_owned
+ class_attributes[:feature_category] = :not_owned
end
def get_feature_category
- get_worker_attribute(:feature_category)
+ get_class_attribute(:feature_category)
end
def feature_category_not_owned?
- get_worker_attribute(:feature_category) == :not_owned
+ get_feature_category == :not_owned
end
# This should be set to :high for jobs that need to be run
@@ -61,97 +62,76 @@ module WorkerAttributes
def urgency(urgency)
raise "Invalid urgency: #{urgency}" unless VALID_URGENCIES.include?(urgency)
- worker_attributes[:urgency] = urgency
+ class_attributes[:urgency] = urgency
end
def get_urgency
- worker_attributes[:urgency] || :low
+ class_attributes[:urgency] || :low
end
# Set this attribute on a job when it will call to services outside of the
# application, such as 3rd party applications, other k8s clusters etc See
- # doc/development/sidekiq_style_guide.md#Jobs-with-External-Dependencies for
+ # doc/development/sidekiq_style_guide.md#jobs-with-external-dependencies for
# details
def worker_has_external_dependencies!
- worker_attributes[:external_dependencies] = true
+ class_attributes[:external_dependencies] = true
end
# Returns a truthy value if the worker has external dependencies.
- # See doc/development/sidekiq_style_guide.md#Jobs-with-External-Dependencies
+ # See doc/development/sidekiq_style_guide.md#jobs-with-external-dependencies
# for details
def worker_has_external_dependencies?
- worker_attributes[:external_dependencies]
+ class_attributes[:external_dependencies]
end
def worker_resource_boundary(boundary)
raise "Invalid boundary" unless VALID_RESOURCE_BOUNDARIES.include? boundary
- worker_attributes[:resource_boundary] = boundary
+ class_attributes[:resource_boundary] = boundary
end
def get_worker_resource_boundary
- worker_attributes[:resource_boundary] || :unknown
+ class_attributes[:resource_boundary] || :unknown
end
def idempotent!
- worker_attributes[:idempotent] = true
+ class_attributes[:idempotent] = true
end
def idempotent?
- worker_attributes[:idempotent]
+ class_attributes[:idempotent]
end
def weight(value)
- worker_attributes[:weight] = value
+ class_attributes[:weight] = value
end
def get_weight
- worker_attributes[:weight] ||
+ class_attributes[:weight] ||
NAMESPACE_WEIGHTS[queue_namespace] ||
1
end
def tags(*values)
- worker_attributes[:tags] = values
+ class_attributes[:tags] = values
end
def get_tags
- Array(worker_attributes[:tags])
+ Array(class_attributes[:tags])
end
def deduplicate(strategy, options = {})
- worker_attributes[:deduplication_strategy] = strategy
- worker_attributes[:deduplication_options] = options
+ class_attributes[:deduplication_strategy] = strategy
+ class_attributes[:deduplication_options] = options
end
def get_deduplicate_strategy
- worker_attributes[:deduplication_strategy] ||
+ class_attributes[:deduplication_strategy] ||
Gitlab::SidekiqMiddleware::DuplicateJobs::DuplicateJob::DEFAULT_STRATEGY
end
def get_deduplication_options
- worker_attributes[:deduplication_options] || {}
- end
-
- protected
-
- # Returns a worker attribute declared on this class or its parent class.
- # This approach allows declared attributes to be inherited by
- # child classes.
- def get_worker_attribute(name)
- worker_attributes[name] || superclass_worker_attributes(name)
- end
-
- private
-
- def worker_attributes
- @attributes ||= {}
- end
-
- def superclass_worker_attributes(name)
- return unless superclass.include? WorkerAttributes
-
- superclass.get_worker_attribute(name)
+ class_attributes[:deduplication_options] || {}
end
end
end