summaryrefslogtreecommitdiff
path: root/app/workers/issues/reschedule_stuck_issue_rebalances_worker.rb
blob: d1759589cc0108870767ae50cc2d16db48ca2c85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

module Issues
  class RescheduleStuckIssueRebalancesWorker
    include ApplicationWorker
    include CronjobQueue

    data_consistency :sticky

    idempotent!
    urgency :low
    feature_category :team_planning
    deduplicate :until_executed, including_scheduled: true

    def perform
      namespace_ids, project_ids = ::Gitlab::Issues::Rebalancing::State.fetch_rebalancing_groups_and_projects

      return if namespace_ids.blank? && project_ids.blank?

      namespaces = Namespace.id_in(namespace_ids)
      projects = Project.id_in(project_ids)

      IssueRebalancingWorker.bulk_perform_async_with_contexts(
        namespaces,
        arguments_proc: -> (namespace) { [nil, nil, namespace.id] },
        context_proc: -> (namespace) { { namespace: namespace } }
      )

      IssueRebalancingWorker.bulk_perform_async_with_contexts(
        projects,
        arguments_proc: -> (project) { [nil, project.id, nil] },
        context_proc: -> (project) { { project: project } }
      )
    end
  end
end