2014-06-19 20:35:53 +01:00
|
|
|
module AbfWorkerService
|
|
|
|
class PlatformMetadata < Base
|
|
|
|
|
|
|
|
attr_accessor :platform
|
|
|
|
|
|
|
|
def initialize(platform)
|
|
|
|
@platform = platform
|
|
|
|
end
|
|
|
|
|
|
|
|
def regenerate!
|
2014-06-19 21:44:56 +01:00
|
|
|
return unless can_regenerate?
|
2014-06-19 20:35:53 +01:00
|
|
|
|
2016-05-28 19:21:02 +01:00
|
|
|
Sidekiq::Client.push(
|
|
|
|
'queue' => 'publish_worker_default',
|
2014-06-19 20:35:53 +01:00
|
|
|
'class' => 'AbfWorker::PublishWorkerDefault',
|
|
|
|
'args' => [{
|
|
|
|
id: Time.now.to_i,
|
2014-06-19 21:44:56 +01:00
|
|
|
cmd_params: cmd_params,
|
2014-06-19 20:35:53 +01:00
|
|
|
main_script: 'regenerate_platform_metadata.sh',
|
|
|
|
platform: {
|
|
|
|
platform_path: "#{platform.path}/repository",
|
|
|
|
type: platform.distrib_type,
|
|
|
|
name: platform.name,
|
|
|
|
arch: 'x86_64'
|
|
|
|
},
|
|
|
|
time_living: 9600, # 160 min
|
|
|
|
extra: {platform_id: platform.id, regenerate_platform: true}
|
|
|
|
}]
|
|
|
|
) if platform.start_regeneration
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def can_regenerate?
|
|
|
|
repos = platform.repositories
|
|
|
|
return false if repos.find{ |r| r.repo_lock_file_exists? }
|
|
|
|
|
|
|
|
statuses = RepositoryStatus.where(platform_id: platform.id)
|
|
|
|
return true if statuses.blank?
|
|
|
|
|
|
|
|
statuses = statuses.map do |s|
|
|
|
|
s.ready? || s.can_start_regeneration? || s.can_start_resign?
|
|
|
|
end.uniq
|
|
|
|
statuses == [true]
|
|
|
|
end
|
|
|
|
|
|
|
|
def cmd_params
|
|
|
|
{
|
|
|
|
'RELEASED' => platform.released,
|
|
|
|
'REPOSITORY_NAMES' => platform.repositories.map(&:name).join(','),
|
|
|
|
'TYPE' => platform.distrib_type,
|
|
|
|
'REGENERATE_PLATFORM_METADATA' => true,
|
|
|
|
'SAVE_TO_PLATFORM' => platform.name,
|
|
|
|
'BUILD_FOR_PLATFORM' => platform.name
|
|
|
|
}.map{ |k, v| "#{k}=#{v}" }.join(' ')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|