Class: ContainerExpirationPolicy

Inherits:
ApplicationRecord show all
Includes:
Schedulable, UsageStatistics
Defined in:
app/models/container_expiration_policy.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Schedulable

#schedule_next_run!

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details

.cadence_optionsObject


33
34
35
36
37
38
39
40
41
# File 'app/models/container_expiration_policy.rb', line 33

def self.cadence_options
  {
    '1d': _('Every day'),
    '7d': _('Every week'),
    '14d': _('Every two weeks'),
    '1month': _('Every month'),
    '3month': _('Every three months')
  }
end

.keep_n_optionsObject


22
23
24
25
26
27
28
29
30
31
# File 'app/models/container_expiration_policy.rb', line 22

def self.keep_n_options
  {
    1 => _('%{tags} tag per image name') % { tags: 1 },
    5 => _('%{tags} tags per image name') % { tags: 5 },
    10 => _('%{tags} tags per image name') % { tags: 10 },
    25 => _('%{tags} tags per image name') % { tags: 25 },
    50 => _('%{tags} tags per image name') % { tags: 50 },
    100 => _('%{tags} tags per image name') % { tags: 100 }
  }
end

.older_than_optionsObject


43
44
45
46
47
48
49
50
# File 'app/models/container_expiration_policy.rb', line 43

def self.older_than_options
  {
    '7d': _('%{days} days until tags are automatically removed') % { days: 7 },
    '14d': _('%{days} days until tags are automatically removed') % { days: 14 },
    '30d': _('%{days} days until tags are automatically removed') % { days: 30 },
    '90d': _('%{days} days until tags are automatically removed') % { days: 90 }
  }
end

Instance Method Details

#disable!Object


56
57
58
# File 'app/models/container_expiration_policy.rb', line 56

def disable!
  update_attribute(:enabled, false)
end

#set_next_run_atObject


52
53
54
# File 'app/models/container_expiration_policy.rb', line 52

def set_next_run_at
  self.next_run_at = Time.zone.now + ChronicDuration.parse(cadence).seconds
end