debian-mirror-gitlab/app/models/namespace/aggregation_schedule.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
class Namespace::AggregationSchedule < ApplicationRecord
include AfterCommitQueue
include ExclusiveLeaseGuard
self.primary_key = :namespace_id
2019-12-04 20:38:33 +05:30
REDIS_SHARED_KEY = 'gitlab:update_namespace_statistics_delay'
2019-09-30 21:07:59 +05:30
belongs_to :namespace
after_create :schedule_root_storage_statistics
2023-07-09 08:55:56 +05:30
def default_lease_timeout
if Feature.enabled?(:reduce_aggregation_schedule_lease, namespace.root_ancestor)
2.minutes.to_i
2022-11-25 23:54:43 +05:30
else
2023-07-09 08:55:56 +05:30
30.minutes.to_i
2022-11-25 23:54:43 +05:30
end
end
2019-09-30 21:07:59 +05:30
def schedule_root_storage_statistics
run_after_commit_or_now do
try_obtain_lease do
Namespaces::RootStatisticsWorker
.perform_async(namespace_id)
Namespaces::RootStatisticsWorker
2023-07-09 08:55:56 +05:30
.perform_in(default_lease_timeout, namespace_id)
2019-09-30 21:07:59 +05:30
end
end
end
private
# Used by ExclusiveLeaseGuard
def lease_timeout
2023-07-09 08:55:56 +05:30
default_lease_timeout
2019-09-30 21:07:59 +05:30
end
# Used by ExclusiveLeaseGuard
def lease_key
"namespace:namespaces_root_statistics:#{namespace_id}"
end
# Used by ExclusiveLeaseGuard
# Overriding value as we never release the lease
# before the timeout in order to prevent multiple
# RootStatisticsWorker to start in a short span of time
def lease_release?
false
end
end