Class: Deployments::ArchiveInProjectService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/deployments/archive_in_project_service.rb

Overview

This service archives old deploymets and deletes deployment refs for keeping the project repository performant.

Constant Summary collapse

BATCH_SIZE =
100

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

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/services/deployments/archive_in_project_service.rb', line 9

def execute
  deployments = Deployment.archivables_in(project, limit: BATCH_SIZE)

  return success(result: :empty) if deployments.empty?

  ids = deployments.map(&:id)
  ref_paths = deployments.map(&:ref_path)

  project.repository.delete_refs(*ref_paths)
  project.deployments.id_in(ids).update_all(archived: true)

  success(result: :archived, count: ids.count)
end