2019-07-02 10:44:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Namespaces
|
2020-03-31 17:08:05 -04:00
|
|
|
class ScheduleAggregationWorker
|
2019-07-02 10:44:39 -04:00
|
|
|
include ApplicationWorker
|
|
|
|
|
2021-04-30 14:10:09 -04:00
|
|
|
sidekiq_options retry: 3
|
|
|
|
|
2019-07-02 10:44:39 -04:00
|
|
|
queue_namespace :update_namespace_statistics
|
2019-10-18 07:11:44 -04:00
|
|
|
feature_category :source_code_management
|
2020-03-31 17:08:05 -04:00
|
|
|
idempotent!
|
2019-07-02 10:44:39 -04:00
|
|
|
|
|
|
|
def perform(namespace_id)
|
|
|
|
return unless aggregation_schedules_table_exists?
|
|
|
|
|
|
|
|
namespace = Namespace.find(namespace_id)
|
|
|
|
root_ancestor = namespace.root_ancestor
|
|
|
|
|
2019-08-01 16:14:21 -04:00
|
|
|
return if root_ancestor.aggregation_scheduled?
|
2019-07-02 10:44:39 -04:00
|
|
|
|
|
|
|
Namespace::AggregationSchedule.safe_find_or_create_by!(namespace_id: root_ancestor.id)
|
2020-03-09 17:07:57 -04:00
|
|
|
rescue ActiveRecord::RecordNotFound => ex
|
|
|
|
Gitlab::ErrorTracking.track_exception(ex, namespace_id: namespace_id)
|
2019-07-02 10:44:39 -04:00
|
|
|
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-09-18 10:02:45 -04:00
|
|
|
# https://gitlab.com/gitlab-org/gitlab-foss/issues/50712
|
2019-07-02 10:44:39 -04:00
|
|
|
def aggregation_schedules_table_exists?
|
|
|
|
return true unless Rails.env.test?
|
|
|
|
|
|
|
|
Namespace::AggregationSchedule.table_exists?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|