summaryrefslogtreecommitdiff
path: root/app/services/namespaces
diff options
context:
space:
mode:
authorMayra Cabrera <mcabrera@gitlab.com>2019-07-02 14:44:39 +0000
committerKamil TrzciƄski <ayufan@ayufan.eu>2019-07-02 14:44:39 +0000
commitdfdfa913ba9cb74beb7adad0352c5efadec84494 (patch)
tree16d730e52e00d6f921087ec6531ab463447d09f8 /app/services/namespaces
parente07ebe66af957c46e7c69329b3ab561bb539351b (diff)
downloadgitlab-ce-dfdfa913ba9cb74beb7adad0352c5efadec84494.tar.gz
Includes logic to persist namespace statistics
- Add two new ActiveRecord models: - RootNamespaceStoragestatistics will persist root namespace statistics - NamespaceAggregationSchedule will save information when a new update to the namespace statistics needs to be scheduled - Inject into UpdateProjectStatistics concern a new callback that will call an async job to insert a new row onto NamespaceAggregationSchedule table - When a new row is inserted a new job is scheduled. This job will update call an specific service to update the statistics and after that it will delete thee aggregated scheduled row - The RefresherServices makes heavy use of arel to build composable queries to update Namespace::RootStorageStatistics attributes. - Add an extra worker to traverse pending rows on NAmespace::AggregationSchedule table and schedule a worker for each one of this rows. - Add an extra worker to traverse pending rows on NAmespace::AggregationSchedule table and schedule a worker for each one of this rows
Diffstat (limited to 'app/services/namespaces')
-rw-r--r--app/services/namespaces/statistics_refresher_service.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/services/namespaces/statistics_refresher_service.rb b/app/services/namespaces/statistics_refresher_service.rb
new file mode 100644
index 00000000000..c07b302839b
--- /dev/null
+++ b/app/services/namespaces/statistics_refresher_service.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module Namespaces
+ class StatisticsRefresherService
+ RefresherError = Class.new(StandardError)
+
+ def execute(root_namespace)
+ root_storage_statistics = find_or_create_root_storage_statistics(root_namespace.id)
+
+ root_storage_statistics.recalculate!
+ rescue ActiveRecord::ActiveRecordError => e
+ raise RefresherError.new(e.message)
+ end
+
+ private
+
+ def find_or_create_root_storage_statistics(root_namespace_id)
+ Namespace::RootStorageStatistics
+ .safe_find_or_create_by!(namespace_id: root_namespace_id)
+ end
+ end
+end