Class: Packages::Cleanup::Policy

Inherits:
ApplicationRecord show all
Includes:
Schedulable
Defined in:
app/models/packages/cleanup/policy.rb

Constant Summary collapse

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

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Schedulable

#schedule_next_run!

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.activeObject

used by Schedulable



21
22
23
# File 'app/models/packages/cleanup/policy.rb', line 21

def self.active
  where.not(keep_n_duplicated_package_files: 'all')
end

.runnableObject



32
33
34
# File 'app/models/packages/cleanup/policy.rb', line 32

def self.runnable
  runnable_schedules.with_packages.order(next_run_at: :asc)
end

.with_packagesObject



25
26
27
28
29
30
# File 'app/models/packages/cleanup/policy.rb', line 25

def self.with_packages
  exists_select = ::Packages::Package.installable
                   .where('packages_packages.project_id = packages_cleanup_policies.project_id')
                   .select(1)
  where('EXISTS (?)', exists_select)
end

Instance Method Details

#keep_n_duplicated_package_files_disabled?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/packages/cleanup/policy.rb', line 41

def keep_n_duplicated_package_files_disabled?
  keep_n_duplicated_package_files == 'all'
end

#set_next_run_atObject



36
37
38
39
# File 'app/models/packages/cleanup/policy.rb', line 36

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