debian-mirror-gitlab/lib/gitlab/sidekiq_config/worker.rb

81 lines
1.8 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module Gitlab
module SidekiqConfig
class Worker
include Comparable
attr_reader :klass
2021-10-27 15:23:28 +05:30
delegate :feature_category_not_owned?, :generated_queue_name, :get_feature_category,
:get_sidekiq_options, :get_tags, :get_urgency, :get_weight,
2022-07-16 23:28:13 +05:30
:get_worker_resource_boundary, :idempotent?, :queue_namespace, :queue,
2021-10-27 15:23:28 +05:30
:worker_has_external_dependencies?,
2020-03-13 15:44:24 +05:30
to: :klass
2021-12-11 22:18:48 +05:30
def initialize(klass, ee:, jh: false)
2020-03-13 15:44:24 +05:30
@klass = klass
@ee = ee
2021-12-11 22:18:48 +05:30
@jh = jh
2020-03-13 15:44:24 +05:30
end
def ee?
@ee
end
2021-12-11 22:18:48 +05:30
def jh?
@jh
end
2020-03-13 15:44:24 +05:30
def ==(other)
to_yaml == case other
when self.class
other.to_yaml
else
other
end
end
def <=>(other)
to_sort <=> other.to_sort
end
# Put namespaced queues first
def to_sort
2021-10-27 15:23:28 +05:30
[queue_namespace ? 0 : 1, generated_queue_name]
2020-03-13 15:44:24 +05:30
end
# YAML representation
def encode_with(coder)
coder.represent_map(nil, to_yaml)
end
def to_yaml
{
2021-10-27 15:23:28 +05:30
name: generated_queue_name,
2021-06-08 01:23:25 +05:30
worker_name: klass.name,
2020-03-13 15:44:24 +05:30
feature_category: get_feature_category,
has_external_dependencies: worker_has_external_dependencies?,
2020-04-08 14:13:33 +05:30
urgency: get_urgency,
2020-03-13 15:44:24 +05:30
resource_boundary: get_worker_resource_boundary,
2020-04-08 14:13:33 +05:30
weight: get_weight,
2020-06-23 00:09:42 +05:30
idempotent: idempotent?,
tags: get_tags
2020-03-13 15:44:24 +05:30
}
end
def namespace_and_weight
[queue_namespace, get_weight]
end
def queue_and_weight
2021-10-27 15:23:28 +05:30
[generated_queue_name, get_weight]
2020-03-13 15:44:24 +05:30
end
2021-06-08 01:23:25 +05:30
def retries
get_sidekiq_options['retry']
end
2020-03-13 15:44:24 +05:30
end
end
end