Clear archive cache asynchronously

This commit is contained in:
Jacob Vosmaer 2015-10-16 18:39:17 +02:00
parent dad30ec0d6
commit e1fff018d7
5 changed files with 20 additions and 10 deletions

View file

@ -67,6 +67,7 @@ v 8.1.0 (unreleased)
- Only render 404 page from /public
- Hide passwords from services API (Alex Lossent)
- Fix: Images cannot show when projects' path was changed
- Let gitlab-git-http-server generate and serve 'git archive' downloads
v 8.0.4
- Fix Message-ID header to be RFC 2111-compliant to prevent e-mails being dropped (Stan Hu)

View file

@ -8,6 +8,14 @@ class Repository
attr_accessor :raw_repository, :path_with_namespace, :project
def self.clean_old_archives
repository_downloads_path = Gitlab.config.gitlab.repository_downloads_path
return unless File.directory?(repository_downloads_path)
Gitlab::Popen.popen(%W(find #{repository_downloads_path} -not -path #{repository_downloads_path} -mmin +120 -delete))
end
def initialize(path_with_namespace, default_branch = nil, project = nil)
@path_with_namespace = path_with_namespace
@project = project
@ -269,14 +277,6 @@ class Repository
end
# Remove archives older than 2 hours
def clean_old_archives
repository_downloads_path = Gitlab.config.gitlab.repository_downloads_path
return unless File.directory?(repository_downloads_path)
Gitlab::Popen.popen(%W(find #{repository_downloads_path} -not -path #{repository_downloads_path} -mmin +120 -delete))
end
def branches_sorted_by(value)
case value
when 'recently_updated'

View file

@ -7,7 +7,7 @@ class ArchiveRepositoryService
end
def execute(options = {})
project.repository.clean_old_archives
RepositoryArchiveCacheWorker.perform_async
metadata = project.repository.archive_metadata(ref, storage_path, format)
raise "Repository or ref not found" if metadata.empty?

View file

@ -0,0 +1,9 @@
class RepositoryArchiveCacheWorker
include Sidekiq::Worker
sidekiq_options queue: :default
def perform
Repository.clean_old_archives
end
end

View file

@ -6,7 +6,7 @@ describe ArchiveRepositoryService do
describe "#execute" do
it "cleans old archives" do
expect(project.repository).to receive(:clean_old_archives)
expect(RepositoryArchiveCacheWorker).to receive(:perform_async)
subject.execute(timeout: 0.0)
end