Class: Issues::PlacementWorker
- Inherits:
-
Object
- Object
- Issues::PlacementWorker
- Includes:
- ApplicationWorker
- Defined in:
- app/workers/issues/placement_worker.rb
Constant Summary collapse
- QUERY_LIMIT =
Move at most the most recent 100 issues
100
Constants included from ApplicationWorker
ApplicationWorker::LOGGING_EXTRA_KEY, ApplicationWorker::SAFE_PUSH_BULK_LIMIT
Constants included from Gitlab::Loggable
Constants included from WorkerAttributes
WorkerAttributes::DEFAULT_DATA_CONSISTENCY, WorkerAttributes::DEFAULT_DEFER_DELAY, WorkerAttributes::NAMESPACE_WEIGHTS, WorkerAttributes::VALID_DATA_CONSISTENCIES, WorkerAttributes::VALID_RESOURCE_BOUNDARIES, WorkerAttributes::VALID_URGENCIES
Instance Method Summary collapse
- #find_issue(issue_id, project_id) ⇒ Object
-
#perform(issue_id, project_id = nil) ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
Methods included from Gitlab::Loggable
Methods included from Gitlab::SidekiqVersioning::Worker
Methods included from WorkerContext
Instance Method Details
#find_issue(issue_id, project_id) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'app/workers/issues/placement_worker.rb', line 50 def find_issue(issue_id, project_id) return Issue.id_in(issue_id).take if issue_id project = Project.id_in(project_id).take return unless project project.issues.take end |
#perform(issue_id, project_id = nil) ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/workers/issues/placement_worker.rb', line 22 def perform(issue_id, project_id = nil) issue = find_issue(issue_id, project_id) return unless issue # Temporary disable moving null elements because of performance problems # For more information check https://gitlab.com/gitlab-com/gl-infra/production/-/issues/4321 return if issue.blocked_for_repositioning? # Move the oldest 100 unpositioned items to the end. # This is to deal with out-of-order execution of the worker, # while preserving creation order. to_place = Issue .relative_positioning_query_base(issue) .with_null_relative_position .order({ created_at: :asc }, { id: :asc }) .limit(QUERY_LIMIT + 1) .to_a leftover = to_place.pop if to_place.count > QUERY_LIMIT Issue.move_nulls_to_end(to_place) Issues::BaseService.new(container: nil).rebalance_if_needed(to_place.max_by(&:relative_position)) Issues::PlacementWorker.perform_async(nil, leftover.project_id) if leftover.present? rescue RelativePositioning::NoSpaceLeft => e Gitlab::ErrorTracking.log_exception(e, issue_id: issue_id, project_id: project_id) Issues::RebalancingWorker.perform_async(nil, *root_namespace_id_to_rebalance(issue, project_id)) end |