rosa-build/app/jobs/build_lists/dependent_packages_job.rb

61 lines
2.3 KiB
Ruby
Raw Normal View History

2014-06-18 21:40:22 +01:00
module BuildLists
class DependentPackagesJob
@queue = :middle
def self.perform(build_list_id, user_id, project_ids, arch_ids, options)
2014-06-18 21:40:22 +01:00
build_list = BuildList.find(build_list_id)
return if build_list.save_to_platform.personal?
user = User.find(user_id)
2015-03-14 22:10:04 +00:00
return unless BuildListPolicy.new(user, build_list).show?
2014-06-18 21:40:22 +01:00
arches = Arch.where(id: arch_ids).to_a
Project.where(id: project_ids).to_a.each do |project|
2015-03-14 22:10:04 +00:00
next unless ProjectPolicy.new(user, project).write?
2014-06-18 21:40:22 +01:00
build_for_platform = save_to_platform = build_list.build_for_platform
save_to_repository = save_to_platform.repositories.find{ |r| r.projects.exists?(project.id) }
next unless save_to_repository
project_version = project.project_version_for(save_to_platform, build_for_platform)
project.increase_release_tag(project_version, user, "BuildList##{build_list.id}: Increase release tag")
arches.each do |arch|
bl = project.build_lists.build
bl.arch = arch
bl.save_to_repository = save_to_repository
bl.priority = user.build_priority # User builds more priority than mass rebuild with zero priority
bl.project_version = project_version
bl.user = user
bl.include_repos = [build_for_platform.repositories.main.first.try(:id)].compact
bl.include_repos |= [save_to_repository.id]
%i(
build_for_platform_id
update_type
save_to_platform_id
extra_build_lists
extra_params
external_nodes
group_id
).each { |field| bl[field] = build_list[field] }
bl.auto_publish_status = options['auto_publish_status']
%w(
auto_create_container
include_testing_subrepository
use_cached_chroot
use_extra_tests
).each { |field| bl[field] = options[field] }
2015-05-15 13:53:36 +01:00
# debug
begin
bl.save! if BuildListPolicy.new(user, bl).create?
rescue ActiveRecord::RecordInvalid => invalid
raise 'DEBUG: ' + invalid.record.errors.full_messages.join('; ')
2015-05-15 13:53:36 +01:00
end
end
2014-06-18 21:40:22 +01:00
end
end
end
end