Class: RepositoryArchiveCleanUpService

Inherits:
Object
  • Object
show all
Defined in:
app/services/repository_archive_clean_up_service.rb

Overview

RepositoryArchiveCleanUpService removes cached repository archives that are generated on-the-fly by Gitaly. These files are stored in the following form (as defined in lib/gitlab/git/repository.rb) and served by GitLab Workhorse:

/path/to/repository/downloads/project-N/sha/@v2/archive.format

Legacy paths omit the @v2 prefix.

For example:

/var/opt/gitlab/gitlab-rails/shared/cache/archive/project-1/master/@v2/archive.zip

Constant Summary collapse

LAST_MODIFIED_TIME_IN_MINUTES =
120
MAX_ARCHIVE_DEPTH =

For ‘/path/project-N/sha/@v2/archive.zip`, `find /path -maxdepth 4` will find this file

4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mmin = LAST_MODIFIED_TIME_IN_MINUTES) ⇒ RepositoryArchiveCleanUpService

Returns a new instance of RepositoryArchiveCleanUpService.



23
24
25
26
# File 'app/services/repository_archive_clean_up_service.rb', line 23

def initialize(mmin = LAST_MODIFIED_TIME_IN_MINUTES)
  @mmin = mmin
  @path = Gitlab.config.gitlab.repository_downloads_path
end

Instance Attribute Details

#mminObject (readonly)

Returns the value of attribute mmin.



21
22
23
# File 'app/services/repository_archive_clean_up_service.rb', line 21

def mmin
  @mmin
end

#pathObject (readonly)

Returns the value of attribute path.



21
22
23
# File 'app/services/repository_archive_clean_up_service.rb', line 21

def path
  @path
end

Instance Method Details

#executeObject



28
29
30
31
32
33
34
35
# File 'app/services/repository_archive_clean_up_service.rb', line 28

def execute
  Gitlab::Metrics.measure(:repository_archive_clean_up) do
    next unless File.directory?(path)

    clean_up_old_archives
    clean_up_empty_directories
  end
end