#276: updated logic of BuildListsPublishTaskManager

This commit is contained in:
Vokhmin Alexey V 2013-08-25 20:30:23 +04:00
parent 75d5bc501f
commit b8736a03ed
4 changed files with 24 additions and 29 deletions

View File

@ -33,7 +33,7 @@ class Repository < ActiveRecord::Base
end end
def resign def resign
unless platform.personal? if platform.main?
status = repository_statuses.find_or_create_by_platform_id(platform_id) status = repository_statuses.find_or_create_by_platform_id(platform_id)
status.resign status.resign
end end

View File

@ -33,8 +33,8 @@ class RepositoryStatus < ActiveRecord::Base
attr_accessible :platform_id, :repository_id attr_accessible :platform_id, :repository_id
scope :platform_ready, where(:platforms => {:status => READY}).joins(:platform) scope :platform_ready, where(:platforms => {:status => READY}).joins(:platform)
scope :for_regeneration, platform_ready.where(:status => WAITING_FOR_REGENERATION) scope :for_regeneration, where(:status => WAITING_FOR_REGENERATION)
scope :for_resign, platform_ready.where(:status => [WAITING_FOR_RESIGN, WAITING_FOR_RESIGN_AND_REGENERATION]) scope :for_resign, where(:status => [WAITING_FOR_RESIGN, WAITING_FOR_RESIGN_AND_REGENERATION])
scope :not_ready, where('repository_statuses.status != ?', READY) scope :not_ready, where('repository_statuses.status != ?', READY)
state_machine :status, :initial => :ready do state_machine :status, :initial => :ready do

View File

@ -146,7 +146,8 @@ module AbfWorker
private private
def create_tasks_for_resign_repositories def create_tasks_for_resign_repositories
repository_statuses = RepositoryStatus.for_resign.includes(:repository => :platform) repository_statuses = RepositoryStatus.platform_ready.
for_resign.includes(:repository => :platform)
repository_statuses.each do |repository_status| repository_statuses.each do |repository_status|
r = repository_status.repository r = repository_status.repository
# Checks mirror sync status # Checks mirror sync status
@ -175,7 +176,7 @@ module AbfWorker
:type => :resign, :type => :resign,
:skip_feedback => true, :skip_feedback => true,
:time_living => 9600, # 160 min :time_living => 9600, # 160 min
:extra => {:repository_status_ids => [repository_status.id]} :extra => {:repository_status_id => repository_status.id}
}] }]
) if repository_status.start_resign ) if repository_status.start_resign
end end
@ -246,7 +247,7 @@ module AbfWorker
save_to_repository = Repository.find save_to_repository_id save_to_repository = Repository.find save_to_repository_id
# Checks mirror sync status # Checks mirror sync status
return false if save_to_repository.repo_lock_file_exists? return false if save_to_repository.repo_lock_file_exists? || !save_to_repository.platform.ready?
repository_status = save_to_repository.find_or_create_by_platform_id(build_for_platform_id) repository_status = save_to_repository.find_or_create_by_platform_id(build_for_platform_id)
return false unless repository_status.publish return false unless repository_status.publish
@ -282,7 +283,7 @@ module AbfWorker
:repository => {:id => save_to_repository_id}, :repository => {:id => save_to_repository_id},
:type => :publish, :type => :publish,
:time_living => 9600, # 160 min :time_living => 9600, # 160 min
:extra => {:repository_status_ids => [repository_status.id]} :extra => {:repository_status_id => repository_status.id}
} }
packages, build_list_ids, new_sources = self.class.packages_structure, [], {} packages, build_list_ids, new_sources = self.class.packages_structure, [], {}
@ -319,23 +320,20 @@ module AbfWorker
def create_tasks_for_regenerate_metadata_for_software_center def create_tasks_for_regenerate_metadata_for_software_center
Platfor.main.waiting_for_regeneration.each do |platform| Platfor.main.waiting_for_regeneration.each do |platform|
repos = platform.repositories repos = platform.repositories
repos.repositories.each(&:regenerate) statuses = RepositoryStatus.where(:platform_id => platform.id)
statuses = RepositoryStatus.where(:platform_id => platform.id, :repository_id => repos.map(&:id))
next if repos.find{ |r| r.repo_lock_file_exists? } next if repos.find{ |r| r.repo_lock_file_exists? }
next if statuses.find{ |s| !s.can_start_regeneration? } next if statuses.present? &&
statuses.map{ |s| s.ready? || s.can_start_regeneration? || s.can_start_resign? }.uniq == [true]
build_for_platform = repository_statuses.platform
cmd_params = { cmd_params = {
'RELEASED' => platform.released, 'RELEASED' => platform.released,
'REPOSITORY_NAME' => rep.name, 'REPOSITORY_NAME' => platform.repositories.map(&:name).join(','),
'TYPE' => platform.distrib_type, 'TYPE' => platform.distrib_type,
'REGENERATE_PLATFORM_METADATA' => true, 'REGENERATE_PLATFORM_METADATA' => true,
'SAVE_TO_PLATFORM' => platform.name, 'SAVE_TO_PLATFORM' => platform.name,
'BUILD_FOR_PLATFORM' => platform.name 'BUILD_FOR_PLATFORM' => platform.name
}.map{ |k, v| "#{k}=#{v}" }.join(' ') }.map{ |k, v| "#{k}=#{v}" }.join(' ')
statuses.each(&:start_regeneration)
platform.start_regeneration
Resque.push( Resque.push(
'publish_worker_default', 'publish_worker_default',
'class' => 'AbfWorker::PublishWorkerDefault', 'class' => 'AbfWorker::PublishWorkerDefault',
@ -343,24 +341,25 @@ module AbfWorker
:id => Time.now.to_i, :id => Time.now.to_i,
:cmd_params => cmd_params, :cmd_params => cmd_params,
:platform => { :platform => {
:platform_path => "#{rep.platform.path}/repository", :platform_path => "#{platform.path}/repository",
:type => platform.distrib_type, :type => platform.distrib_type,
:name => platform.name, :name => platform.name,
:arch => 'x86_64' :arch => 'x86_64'
}, },
:repository => {:id => rep.id}, :repository => {:id => platform.repositories.first.id},
:type => :publish, :type => :publish,
:time_living => 9600, # 160 min :time_living => 9600, # 160 min
:skip_feedback => true, :skip_feedback => true,
:extra => {:repository_status_ids => statuses.map(&:id), :regenerate_platform => true} :extra => {:platform_id => platform.id, :regenerate_platform => true}
}] }]
) ) if platform.start_regeneration
end end
end end
def create_tasks_for_repository_regenerate_metadata def create_tasks_for_repository_regenerate_metadata
repository_statuses = RepositoryStatus.for_regeneration.includes(:repository => :platform) repository_statuses = RepositoryStatus.platform_ready.
for_regeneration.includes(:repository => :platform)
repository_statuses.each do |repository_status| repository_statuses.each do |repository_status|
rep = repository_status.repository rep = repository_status.repository
# Checks mirror sync status # Checks mirror sync status
@ -392,7 +391,7 @@ module AbfWorker
:type => :publish, :type => :publish,
:time_living => 9600, # 160 min :time_living => 9600, # 160 min
:skip_feedback => true, :skip_feedback => true,
:extra => {:repository_status_ids => [repository_status.id], :regenerate => true} :extra => {:repository_status_id => repository_status.id, :regenerate => true}
}] }]
) if repository_status.start_regeneration ) if repository_status.start_regeneration
end end

View File

@ -9,17 +9,13 @@ module AbfWorker
def perform def perform
return if status == STARTED # do nothing when publication started return if status == STARTED # do nothing when publication started
repository_statuses = RepositoryStatus.where(:id => options['extra']['repository_status_ids']) repository_status = RepositoryStatus.where(:id => options['extra']['repository_status_id'])
begin begin
if options['extra']['regenerate'] # Regenerate metadata if options['extra']['regenerate'] # Regenerate metadata
last_regenerated_at = Time.now.utc repository_status.last_regenerated_at = Time.now.utc
repository_statuses.each do |repository_status| repository_status.last_regenerated_status = status
repository_status.last_regenerated_at = last_regenerated_at
repository_status.last_regenerated_status = status
end
elsif options['extra']['regenerate_platform'] # Regenerate metadata for Software Center elsif options['extra']['regenerate_platform'] # Regenerate metadata for Software Center
platform = repository_statuses.first.try(:platform) if platform = Platform.where(:id => options['extra']['platform_id'])).first
if platform
platform.last_regenerated_at = Time.now.utc platform.last_regenerated_at = Time.now.utc
platform.last_regenerated_status = status platform.last_regenerated_status = status
platform.ready platform.ready
@ -36,7 +32,7 @@ module AbfWorker
update_rpm_builds update_rpm_builds
end end
ensure ensure
repository_statuses.map(&:ready) if repository_statuses.present? repository_status.ready if repository_status.present?
end end
end end