#336: added ability for clean up packages from testing repository
This commit is contained in:
parent
ad4b25d281
commit
df83fe65e1
|
@ -158,6 +158,7 @@ class BuildList < ActiveRecord::Base
|
||||||
after_transition :on => :published,
|
after_transition :on => :published,
|
||||||
:do => [:set_version_and_tag, :actualize_packages]
|
:do => [:set_version_and_tag, :actualize_packages]
|
||||||
after_transition :on => :publish, :do => :set_publisher
|
after_transition :on => :publish, :do => :set_publisher
|
||||||
|
after_transition :build_published_into_testing => :publish, :do => :cleanup_packages_from_testing
|
||||||
after_transition :on => :cancel, :do => :cancel_job
|
after_transition :on => :cancel, :do => :cancel_job
|
||||||
|
|
||||||
after_transition :on => [:published, :fail_publish, :build_error, :tests_failed], :do => :notify_users
|
after_transition :on => [:published, :fail_publish, :build_error, :tests_failed], :do => :notify_users
|
||||||
|
@ -540,6 +541,14 @@ class BuildList < ActiveRecord::Base
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cleanup_packages_from_testing
|
||||||
|
AbfWorker::BuildListsPublishTaskManager.cleanup_packages_from_testing(
|
||||||
|
build_for_platform_id,
|
||||||
|
save_to_repository_id,
|
||||||
|
id
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def current_ability
|
def current_ability
|
||||||
@current_ability ||= Ability.new(user)
|
@current_ability ||= Ability.new(user)
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,9 @@ module AbfWorker
|
||||||
%w(PROJECTS_FOR_CLEANUP
|
%w(PROJECTS_FOR_CLEANUP
|
||||||
LOCKED_PROJECTS_FOR_CLEANUP
|
LOCKED_PROJECTS_FOR_CLEANUP
|
||||||
LOCKED_BUILD_LISTS
|
LOCKED_BUILD_LISTS
|
||||||
PACKAGES_FOR_CLEANUP).each do |kind|
|
PACKAGES_FOR_CLEANUP
|
||||||
|
REP_AND_PLS_OF_BUILD_LISTS_FOR_CLEANUP_FROM_TESTING
|
||||||
|
BUILD_LISTS_FOR_CLEANUP_FROM_TESTING).each do |kind|
|
||||||
const_set kind, "#{REDIS_MAIN_KEY}#{kind.downcase.gsub('_', '-')}"
|
const_set kind, "#{REDIS_MAIN_KEY}#{kind.downcase.gsub('_', '-')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,6 +60,13 @@ module AbfWorker
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cleanup_packages_from_testing(platform_id, repository_id, *build_lists)
|
||||||
|
return if build_lists.blank?
|
||||||
|
key = "#{BUILD_LISTS_FOR_CLEANUP_FROM_TESTING}-#{repository_id}-#{platform_id}"
|
||||||
|
redis.lpush REP_AND_PLS_OF_BUILD_LISTS_FOR_CLEANUP_FROM_TESTING, "#{repository_id}-#{platform_id}"
|
||||||
|
redis.lpush key, build_lists
|
||||||
|
end
|
||||||
|
|
||||||
def unlock_build_list(build_list)
|
def unlock_build_list(build_list)
|
||||||
redis.lrem LOCKED_BUILD_LISTS, 0, build_list.id
|
redis.lrem LOCKED_BUILD_LISTS, 0, build_list.id
|
||||||
end
|
end
|
||||||
|
@ -213,8 +222,15 @@ module AbfWorker
|
||||||
locked_rep.present? && locked_rep.include?(rep.to_i) ? nil : [rep.to_i, pl.to_i]
|
locked_rep.present? && locked_rep.include?(rep.to_i) ? nil : [rep.to_i, pl.to_i]
|
||||||
end.compact
|
end.compact
|
||||||
|
|
||||||
|
for_cleanup_from_testing = @redis.lrange(REP_AND_PLS_OF_BUILD_LISTS_FOR_CLEANUP_FROM_TESTING, 0, -1).map do |key|
|
||||||
|
next if redis.llen("#{BUILD_LISTS_FOR_CLEANUP_FROM_TESTING}-#{key}") == 0
|
||||||
|
rep, pl = *key.split('-')
|
||||||
|
locked_rep.present? && locked_rep.include?(rep.to_i) ? nil : [rep.to_i, pl.to_i]
|
||||||
|
end.compact if testing
|
||||||
|
for_cleanup_from_testing ||= []
|
||||||
|
|
||||||
counter = 1
|
counter = 1
|
||||||
available_repos = available_repos.map{ |bl| [bl.save_to_repository_id, bl.build_for_platform_id] } | for_cleanup
|
available_repos = available_repos.map{ |bl| [bl.save_to_repository_id, bl.build_for_platform_id] } | for_cleanup | for_cleanup_from_testing
|
||||||
available_repos.each do |save_to_repository_id, build_for_platform_id|
|
available_repos.each do |save_to_repository_id, build_for_platform_id|
|
||||||
next if RepositoryStatus.not_ready.where(:repository_id => save_to_repository_id, :platform_id => build_for_platform_id).exists?
|
next if RepositoryStatus.not_ready.where(:repository_id => save_to_repository_id, :platform_id => build_for_platform_id).exists?
|
||||||
break if counter > @workers_count
|
break if counter > @workers_count
|
||||||
|
@ -258,6 +274,18 @@ module AbfWorker
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if testing
|
||||||
|
build_lists_for_cleanup_from_testing = @redis.lrange(
|
||||||
|
"#{BUILD_LISTS_FOR_CLEANUP_FROM_TESTING}-#{save_to_repository_id}-#{build_for_platform_id}"
|
||||||
|
0, -1
|
||||||
|
)
|
||||||
|
BuildList.where(:id => build_lists_for_cleanup_from_testing).each do |b|
|
||||||
|
self.class.fill_packages(b, old_packages)
|
||||||
|
end if build_lists_for_cleanup_from_testing.present?
|
||||||
|
end
|
||||||
|
build_lists_for_cleanup_from_testing ||= []
|
||||||
|
|
||||||
|
|
||||||
bl = build_lists.first
|
bl = build_lists.first
|
||||||
return false if !bl && old_packages[:sources].empty?
|
return false if !bl && old_packages[:sources].empty?
|
||||||
|
|
||||||
|
@ -301,7 +329,10 @@ module AbfWorker
|
||||||
},
|
},
|
||||||
:repository => {:id => save_to_repository_id},
|
:repository => {:id => save_to_repository_id},
|
||||||
:time_living => 9600, # 160 min
|
:time_living => 9600, # 160 min
|
||||||
:extra => {:repository_status_id => repository_status.id}
|
:extra => {
|
||||||
|
:repository_status_id => repository_status.id,
|
||||||
|
:build_lists_for_cleanup_from_testing => build_lists_for_cleanup_from_testing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
packages, build_list_ids, new_sources = self.class.packages_structure, [], {}
|
packages, build_list_ids, new_sources = self.class.packages_structure, [], {}
|
||||||
|
@ -337,6 +368,10 @@ module AbfWorker
|
||||||
@redis.lpush LOCKED_PROJECTS_FOR_CLEANUP, key
|
@redis.lpush LOCKED_PROJECTS_FOR_CLEANUP, key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
build_lists_for_cleanup_from_testing.each do |key|
|
||||||
|
@redis.lrem "#{BUILD_LISTS_FOR_CLEANUP_FROM_TESTING}-#{save_to_repository_id}-#{build_for_platform_id}", 0, key
|
||||||
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,14 @@ module AbfWorker
|
||||||
end
|
end
|
||||||
update_results
|
update_results
|
||||||
elsif !extra['resign'] # Simple publish
|
elsif !extra['resign'] # Simple publish
|
||||||
|
bls = extra['build_lists_for_cleanup_from_testing']
|
||||||
|
if status != COMPLETED && bls.present?
|
||||||
|
AbfWorker::BuildListsPublishTaskManager.cleanup_packages_from_testing(
|
||||||
|
repository_status.platform_id,
|
||||||
|
repository_status.repository_id,
|
||||||
|
bls
|
||||||
|
)
|
||||||
|
end
|
||||||
update_rpm_builds
|
update_rpm_builds
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
|
|
Loading…
Reference in New Issue