2013-09-30 17:35:56 +01:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
class Api::V1::JobsController < Api::V1::BaseController
|
|
|
|
QUEUES = %w(iso_worker_observer publish_observer rpm_worker_observer)
|
|
|
|
QUEUE_CLASSES = %w(AbfWorker::IsoWorkerObserver AbfWorker::PublishObserver AbfWorker::RpmWorkerObserver)
|
|
|
|
|
|
|
|
before_filter :authenticate_user!
|
|
|
|
|
|
|
|
def shift
|
2013-10-17 19:00:15 +01:00
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
build_lists = BuildList.for_status(BuildList::BUILD_PENDING).oldest.order(:create_at)
|
|
|
|
if current_user.system?
|
|
|
|
build_list = build_lists.not_owned_external_nodes.first
|
|
|
|
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
|
|
|
|
end
|
|
|
|
build_list.touch if build_list
|
2013-09-30 17:35:56 +01:00
|
|
|
end
|
|
|
|
|
2013-10-17 19:00:15 +01:00
|
|
|
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
|
2013-10-17 19:00:15 +01:00
|
|
|
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 feedback
|
2013-10-02 16:46:40 +01:00
|
|
|
worker_queue = params[:worker_queue]
|
|
|
|
worker_class = params[:worker_class]
|
2013-09-30 17:35:56 +01:00
|
|
|
if QUEUES.include?(worker_queue) && QUEUE_CLASSES.include?(worker_class)
|
|
|
|
Resque.push worker_queue, 'class' => worker_class, 'args' => params[:worker_args]
|
|
|
|
render :nothing => true
|
|
|
|
else
|
|
|
|
render :nothing => true, :status => 403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|