rosa-build/app/controllers/api/v1/jobs_controller.rb

73 lines
2.6 KiB
Ruby
Raw Normal View History

2013-09-30 17:35:56 +01:00
# -*- encoding : utf-8 -*-
class Api::V1::JobsController < Api::V1::BaseController
2013-10-17 19:22:40 +01:00
# QUEUES = %w(iso_worker_observer publish_observer rpm_worker_observer)
# QUEUE_CLASSES = %w(AbfWorker::IsoWorkerObserver AbfWorker::PublishObserver AbfWorker::RpmWorkerObserver)
QUEUES = %w(rpm_worker_observer)
QUEUE_CLASSES = %w(AbfWorker::RpmWorkerObserver)
2013-09-30 17:35:56 +01:00
before_filter :authenticate_user!
def shift
platform_ids = Platform.where(name: params[:platforms].split(',')).pluck(:id) if params[:platforms].present?
arch_ids = Arch.where(name: params[:arches].split(',')).pluck(:id) if params[:arches].present?
2013-10-28 17:49:50 +00:00
build_lists = BuildList.for_status(BuildList::BUILD_PENDING).scoped_to_arch(arch_ids).
oldest.order(:created_at)
build_lists = build_lists.for_platform(platform_ids) if platform_ids.present?
ActiveRecord::Base.transaction do
if current_user.system?
2013-10-28 17:49:50 +00:00
if task = (Resque.pop('rpm_worker_default') || Resque.pop('rpm_worker'))
@build_list = BuildList.where(:id => task['args'][0]['id']).first
2013-10-25 14:24:59 +01:00
end
2013-10-28 17:49:50 +00:00
@build_list ||= build_lists.external_nodes(:everything).first
@build_list.touch if @build_list
else
@build_list = build_lists.external_nodes(:owned).for_user(current_user).first
@build_list ||= build_lists.external_nodes(:everything).
accessible_by(current_ability, :everything).first
2013-10-17 19:22:40 +01:00
if @build_list
@build_list.builder = current_user
@build_list.save
2013-10-17 19:22:40 +01:00
end
end
2013-09-30 17:35:56 +01:00
end
if @build_list
job = {
:worker_queue => @build_list.worker_queue_with_priority,
:worker_class => @build_list.worker_queue_class,
:worker_args => [@build_list.abf_worker_args]
}
2013-09-30 17:35:56 +01:00
end
render :json => { :job => job }.to_json
2013-09-30 17:35:56 +01:00
end
def status
render :text => Resque.redis.get(params[:key])
end
def logs
name = params[:name]
if name =~ /abfworker::rpm-worker/
if current_user.system? || current_user.id == BuildList.where(:id => name.gsub(/[^\d]/, '')).first.try(:builder_id)
BuildList.log_server.setex name, 15, params[:logs]
end
end
render :nothing => true
end
2013-09-30 17:35:56 +01:00
def feedback
2013-10-02 16:46:40 +01:00
worker_queue = params[:worker_queue]
worker_class = params[:worker_class]
2013-10-18 14:17:29 +01:00
if QUEUES.include?(worker_queue) && QUEUE_CLASSES.include?(worker_class)
2013-10-17 19:22:40 +01:00
worker_args = (params[:worker_args] || []).first || {}
worker_args = worker_args.merge(:feedback_from_user => current_user.id)
2013-10-18 14:17:29 +01:00
Resque.push worker_queue, 'class' => worker_class, 'args' => [worker_args]
2013-09-30 17:35:56 +01:00
render :nothing => true
else
render :nothing => true, :status => 403
end
end
end