From ce3650e03da1b3b054f8d8a12deae15374713fc8 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 30 Sep 2013 20:35:56 +0400 Subject: [PATCH] #312: added Api::V1::JobsController --- app/controllers/api/v1/jobs_controller.rb | 44 +++++++++++++++++++++++ app/models/build_list.rb | 5 +++ config/routes.rb | 9 +++++ 3 files changed, 58 insertions(+) create mode 100644 app/controllers/api/v1/jobs_controller.rb diff --git a/app/controllers/api/v1/jobs_controller.rb b/app/controllers/api/v1/jobs_controller.rb new file mode 100644 index 000000000..8c935c494 --- /dev/null +++ b/app/controllers/api/v1/jobs_controller.rb @@ -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 diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 1fcbd2d24..2232d2f82 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -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 = [] diff --git a/config/routes.rb b/config/routes.rb index 9efc3be31..1e3b019bf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'