#312: added Api::V1::JobsController
This commit is contained in:
parent
0ad1555fc2
commit
ce3650e03d
|
@ -0,0 +1,44 @@
|
|||
# -*- 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
|
||||
if current_user.system?
|
||||
queues = params[:worker_queues].split(',')
|
||||
else
|
||||
queues = BuildList.queues_for current_user
|
||||
end
|
||||
|
||||
if queue = queues.find{ |q| job = Resque.redis.lpop "queue:#{q}" }
|
||||
job = JSON.parse job
|
||||
render :json => {
|
||||
:job => {
|
||||
:worker_queue => queue,
|
||||
:worker_class => job['class'],
|
||||
:worker_args => job['args']
|
||||
}
|
||||
}.to_json
|
||||
else
|
||||
render :nothing => true
|
||||
end
|
||||
end
|
||||
|
||||
def status
|
||||
render :text => Resque.redis.get(params[:key])
|
||||
end
|
||||
|
||||
def feedback
|
||||
worker_queue = params[:worker_queue])
|
||||
worker_class = params[:worker_class])
|
||||
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
|
|
@ -341,6 +341,11 @@ class BuildList < ActiveRecord::Base
|
|||
HUMAN_STATUSES.key human
|
||||
end
|
||||
|
||||
# TODO
|
||||
def self.queues_for(user)
|
||||
nil
|
||||
end
|
||||
|
||||
def set_items(items_hash)
|
||||
self.items = []
|
||||
|
||||
|
|
|
@ -99,6 +99,15 @@ Rosa::Application.routes.draw do
|
|||
resources :product_build_lists, :only => [:index, :show, :destroy, :create, :update] do
|
||||
put :cancel, :on => :member
|
||||
end
|
||||
|
||||
resources :jobs do
|
||||
collection do
|
||||
get :shift
|
||||
get :status
|
||||
put :feedback
|
||||
end
|
||||
end
|
||||
|
||||
#resources :ssh_keys, :only => [:index, :create, :destroy]
|
||||
get 'issues' => 'issues#all_index'
|
||||
get 'pull_requests' => 'pull_requests#all_index'
|
||||
|
|
Loading…
Reference in New Issue