File: data_transfer.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (33 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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
    include CounterAttribute

    self.table_name = 'project_data_transfers'

    belongs_to :project
    belongs_to :namespace

    scope :current_month, -> { where(date: beginning_of_month) }
    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)
    }

    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

    def self.beginning_of_month(time = Time.current)
      time.utc.beginning_of_month
    end
  end
end