debian-mirror-gitlab/app/models/projects/data_transfer.rb

35 lines
1.1 KiB
Ruby
Raw Normal View History

2023-04-23 21:23:45 +05:30
# frozen_string_literal: true
# Tracks egress of various services per project
# This class ensures that we keep 1 record per project per month.
module Projects
class DataTransfer < ApplicationRecord
2023-05-27 22:25:52 +05:30
include AfterCommitQueue
include CounterAttribute
2023-04-23 21:23:45 +05:30
self.table_name = 'project_data_transfers'
belongs_to :project
belongs_to :namespace
scope :current_month, -> { where(date: beginning_of_month) }
2023-06-20 00:43:36 +05:30
scope :with_project_between_dates, ->(project, from, to) {
where(project: project, date: from..to)
}
scope :with_namespace_between_dates, ->(namespace, from, to) {
where(namespace: namespace, date: from..to)
.group(:date, :namespace_id)
.order(date: :desc)
}
2023-04-23 21:23:45 +05:30
2023-05-27 22:25:52 +05:30
counter_attribute :repository_egress, returns_current: true
counter_attribute :artifacts_egress, returns_current: true
counter_attribute :packages_egress, returns_current: true
counter_attribute :registry_egress, returns_current: true
2023-04-23 21:23:45 +05:30
def self.beginning_of_month(time = Time.current)
time.utc.beginning_of_month
end
end
end