Commit 9d706b46 authored by Alexandru Croitor's avatar Alexandru Croitor

Code review changes

Also moved the method to fetch rebalancing containers to
the class responsible with reading rebalance related data
from Redis, ::Gitlab::Issues::Rebalancing::State
parent 57f961a7
...@@ -356,7 +356,7 @@ ...@@ -356,7 +356,7 @@
:tags: [] :tags: []
- :name: cronjob:issues_reschedule_stuck_issue_rebalances - :name: cronjob:issues_reschedule_stuck_issue_rebalances
:worker_name: Issues::RescheduleStuckIssueRebalancesWorker :worker_name: Issues::RescheduleStuckIssueRebalancesWorker
:feature_category: :issue_tracking :feature_category: :team_planning
:has_external_dependencies: :has_external_dependencies:
:urgency: :low :urgency: :low
:resource_boundary: :unknown :resource_boundary: :unknown
......
...@@ -5,15 +5,15 @@ module Issues ...@@ -5,15 +5,15 @@ module Issues
include ApplicationWorker include ApplicationWorker
include CronjobQueue include CronjobQueue
data_consistency :always data_consistency :sticky
idempotent! idempotent!
urgency :low urgency :low
feature_category :issue_tracking feature_category :team_planning
deduplicate :until_executed, including_scheduled: true deduplicate :until_executed, including_scheduled: true
def perform def perform
namespace_ids, project_ids = fetch_rebalancing_groups_and_projects namespace_ids, project_ids = ::Gitlab::Issues::Rebalancing::State.fetch_rebalancing_groups_and_projects
return if namespace_ids.blank? && project_ids.blank? return if namespace_ids.blank? && project_ids.blank?
...@@ -29,31 +29,8 @@ module Issues ...@@ -29,31 +29,8 @@ module Issues
IssueRebalancingWorker.bulk_perform_async_with_contexts( IssueRebalancingWorker.bulk_perform_async_with_contexts(
projects, projects,
arguments_proc: -> (project) { [nil, project.id, nil] }, arguments_proc: -> (project) { [nil, project.id, nil] },
context_proc: -> (project) { { namespace: project } } context_proc: -> (project) { { project: project } }
) )
end end
private
def fetch_rebalancing_groups_and_projects
namespace_ids = []
project_ids = []
all_rebalancing_containers = Gitlab::Redis::SharedState.with do |redis|
redis.smembers(Gitlab::Issues::Rebalancing::State::CONCURRENT_RUNNING_REBALANCES_KEY)
end
all_rebalancing_containers.each do |string|
container_type, container_id = string.split('/', 2).map(&:to_i)
if container_type == Gitlab::Issues::Rebalancing::State::NAMESPACE
namespace_ids << container_id
elsif container_type == Gitlab::Issues::Rebalancing::State::PROJECT
project_ids << container_id
end
end
[namespace_ids, project_ids]
end
end end
end end
...@@ -36,14 +36,12 @@ module Gitlab ...@@ -36,14 +36,12 @@ module Gitlab
end end
def rebalance_in_progress? def rebalance_in_progress?
all_rebalancing_containers = with_redis { |redis| redis.smembers(CONCURRENT_RUNNING_REBALANCES_KEY) }
is_running = case rebalanced_container_type is_running = case rebalanced_container_type
when NAMESPACE when NAMESPACE
namespace_ids = all_rebalancing_containers.map {|string| string.split("#{NAMESPACE}/").second.to_i }.compact namespace_ids = self.class.current_rebalancing_containers.map {|string| string.split("#{NAMESPACE}/").second.to_i }.compact
namespace_ids.include?(root_namespace.id) namespace_ids.include?(root_namespace.id)
when PROJECT when PROJECT
project_ids = all_rebalancing_containers.map {|string| string.split("#{PROJECT}/").second.to_i }.compact project_ids = self.class.current_rebalancing_containers.map {|string| string.split("#{PROJECT}/").second.to_i }.compact
project_ids.include?(projects.take.id) # rubocop:disable CodeReuse/ActiveRecord project_ids.include?(projects.take.id) # rubocop:disable CodeReuse/ActiveRecord
else else
false false
...@@ -131,8 +129,29 @@ module Gitlab ...@@ -131,8 +129,29 @@ module Gitlab
Gitlab::Redis::SharedState.with { |redis| redis.get(recently_finished_key(container_type, container_id)) } Gitlab::Redis::SharedState.with { |redis| redis.get(recently_finished_key(container_type, container_id)) }
end end
def self.fetch_rebalancing_groups_and_projects
namespace_ids = []
project_ids = []
current_rebalancing_containers.each do |string|
container_type, container_id = string.split('/', 2).map(&:to_i)
if container_type == NAMESPACE
namespace_ids << container_id
elsif container_type == PROJECT
project_ids << container_id
end
end
[namespace_ids, project_ids]
end
private private
def self.current_rebalancing_containers
Gitlab::Redis::SharedState.with { |redis| redis.smembers(CONCURRENT_RUNNING_REBALANCES_KEY) }
end
attr_accessor :root_namespace, :projects, :rebalanced_container_type, :rebalanced_container_id attr_accessor :root_namespace, :projects, :rebalanced_container_type, :rebalanced_container_id
def too_many_rebalances_running? def too_many_rebalances_running?
......
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