Class: ContainerExpirationPolicyService

Inherits:
BaseService show all
Defined in:
app/services/container_expiration_policy_service.rb

Constant Summary collapse

InvalidPolicyError =
Class.new(StandardError)

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#execute(container_expiration_policy) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/container_expiration_policy_service.rb', line 6

def execute(container_expiration_policy)
  unless container_expiration_policy.valid?
    container_expiration_policy.disable!
    raise InvalidPolicyError
  end

  container_expiration_policy.schedule_next_run!

  container_expiration_policy.container_repositories.find_each do |container_repository|
    CleanupContainerRepositoryWorker.perform_async(
      nil,
      container_repository.id,
      container_expiration_policy.attributes
        .except('created_at', 'updated_at')
        .merge(container_expiration_policy: true)
    )
  end
end