Skip to content

Commit

Permalink
Delay cleanup of maintenance release repositories
Browse files Browse the repository at this point in the history
After accepting maintenance release requests, the corresponding published
repositories were removed immediately. This broke some automated maintenance
tests because the repositories were removed before the tests finished.

We have moved the cleanup to a delayed job, so the repositories will be removed
some specific time after they are published.
  • Loading branch information
saraycp committed Jan 19, 2021
1 parent a37e001 commit 2737df4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/api/app/jobs/published_repositories_cleanup_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class PublishedRepositoriesCleanupJob < ApplicationJob
def perform(source_project_name)
# cleanup published binaries to save disk space on ftp server and mirrors
Backend::Api::Build::Project.wipe_published_locked(source_project_name)
end
end
11 changes: 9 additions & 2 deletions src/api/app/models/bs_request_action_maintenance_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def per_request_cleanup(opts)

next if cleaned_projects[sprj]

# cleanup published binaries to save disk space on ftp server and mirrors
Backend::Api::Build::Project.wipe_published_locked(sprj)
maintenance_release_cleanup(sprj)
cleaned_projects[sprj] = 1
end
opts[:projectCommit] = {}
Expand Down Expand Up @@ -169,6 +168,14 @@ def sanity_check!
end
end

# Delaying removal of published repositories for accepted maintenance release requests,
# gives some margin to the automated maintenance tests to be finished.
def maintenance_release_cleanup(project_name)
delay = CONFIG['maintenance_release_repositories_lifetime']
set_options = delay ? { wait: delay.seconds } : {}
PublishedRepositoriesCleanupJob.set(set_options).perform_later(project_name)
end

#### Alias of methods
end

Expand Down
4 changes: 4 additions & 0 deletions src/api/config/options.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ default: &default
# icon: sponsor_abc
# url: https://www.example.com

# Lifetime for repositories published after accepting maintenance release requests.
# Default: 2 days (172800 seconds).
# maintenance_release_repositories_lifetime: 172800

production:
<<: *default

Expand Down
6 changes: 5 additions & 1 deletion src/api/test/functional/maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,10 @@ def test_manual_branch_with_extend_names
end

def test_create_maintenance_project_and_release_packages
# FIXME: https://github.com/rails/rails/issues/37270
(ActiveJob::Base.descendants << ActiveJob::Base).each(&:disable_test_adapter)
ActiveJob::Base.queue_adapter = :inline

# Backup
system("for i in #{Rails.root}/tmp/backend_data/projects/BaseDistro2.0.pkg/*.rev; do cp $i $i.backup; done")
# the birthday of J.K.
Expand Down Expand Up @@ -1471,7 +1475,7 @@ def test_create_maintenance_project_and_release_packages
run_scheduler('i586')
run_scheduler('x86_64')
run_publisher
# published binaries from incident got removed?
# Check that the job removed the published binaries
get "/published/#{incident_project}/BaseDistro3/i586/package-1.0-1.i586.rpm"
assert_response 404
get "/published/#{incident_project}/BaseDistro2.0_LinkedUpdateProject/x86_64/package-1.0-1.x86_64.rpm"
Expand Down

0 comments on commit 2737df4

Please sign in to comment.