2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Namespaces
|
2020-04-22 19:07:51 +05:30
|
|
|
class ScheduleAggregationWorker
|
2019-09-30 21:07:59 +05:30
|
|
|
include ApplicationWorker
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
data_consistency :always
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
sidekiq_options retry: 3
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
queue_namespace :update_namespace_statistics
|
2019-12-21 20:55:43 +05:30
|
|
|
feature_category :source_code_management
|
2020-04-22 19:07:51 +05:30
|
|
|
idempotent!
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
def perform(namespace_id)
|
2023-07-09 08:55:56 +05:30
|
|
|
return unless aggregation_schedules_table_exists?
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
namespace = Namespace.find(namespace_id)
|
|
|
|
root_ancestor = namespace.root_ancestor
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
return if root_ancestor.aggregation_scheduled?
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
Namespace::AggregationSchedule.safe_find_or_create_by!(namespace_id: root_ancestor.id)
|
2023-07-09 08:55:56 +05:30
|
|
|
rescue ActiveRecord::RecordNotFound => ex
|
|
|
|
Gitlab::ErrorTracking.track_exception(ex, namespace_id: namespace_id)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# On db/post_migrate/20180529152628_schedule_to_archive_legacy_traces.rb
|
|
|
|
# traces are archived through build.trace.archive, which in consequence
|
|
|
|
# calls UpdateProjectStatistics#schedule_namespace_statistics_worker.
|
|
|
|
#
|
|
|
|
# The migration and specs fails since NamespaceAggregationSchedule table
|
|
|
|
# does not exist at that point.
|
2019-12-04 20:38:33 +05:30
|
|
|
# https://gitlab.com/gitlab-org/gitlab-foss/issues/50712
|
2019-09-30 21:07:59 +05:30
|
|
|
def aggregation_schedules_table_exists?
|
|
|
|
return true unless Rails.env.test?
|
|
|
|
|
|
|
|
Namespace::AggregationSchedule.table_exists?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|