Welcome to mirror list, hosted at ThFree Co, Russian Federation.

policy.rb « cleanup « packages « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d7df90a4ce00c1714913764c0a1be3f4f4b82112 (plain)
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
# frozen_string_literal: true

module Packages
  module Cleanup
    class Policy < ApplicationRecord
      include Schedulable

      KEEP_N_DUPLICATED_PACKAGE_FILES_VALUES = %w[all 1 10 20 30 40 50].freeze

      self.primary_key = :project_id

      belongs_to :project

      validates :project, presence: true
      validates :keep_n_duplicated_package_files,
                inclusion: {
                  in: KEEP_N_DUPLICATED_PACKAGE_FILES_VALUES,
                  message: 'is invalid'
                }

      # used by Schedulable
      def self.active
        where.not(keep_n_duplicated_package_files: 'all')
      end

      def set_next_run_at
        # fixed cadence of 12 hours
        self.next_run_at = Time.zone.now + 12.hours
      end
    end
  end
end