Class: ForemanTasks::Api::TasksController
- Inherits:
-
Api::V2::BaseController
- Object
- Api::V2::BaseController
- ForemanTasks::Api::TasksController
- Includes:
- Foreman::Controller::SmartProxyAuth
- Defined in:
- app/controllers/foreman_tasks/api/tasks_controller.rb
Defined Under Namespace
Classes: BadRequest
Instance Method Summary collapse
- #bulk_resume ⇒ Object
- #bulk_search ⇒ Object
- #callback ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #summary ⇒ Object
Instance Method Details
#bulk_resume ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/foreman_tasks/api/tasks_controller.rb', line 90 def bulk_resume scope = resource_scope scope = scope.search_for(params[:search]) if params[:search] scope = scope.select('DISTINCT foreman_tasks_tasks.*') if params[:search].nil? && params[:task_ids].nil? scope = scope.where(:state => :paused) scope = scope.where(:result => :error) end scope = scope.where(:id => params[:task_ids]) if params[:task_ids] resumed = [] failed = [] skipped = [] scope.each do |task| if task.resumable? begin ForemanTasks.dynflow.world.execute(task.execution_plan.id) resumed << task_hash(task) rescue RuntimeError => e failed << task_hash(task) end else skipped << task_hash(task) end end render :json => { total: resumed.length + failed.length + skipped.length, resumed: resumed, failed: failed, skipped: skipped } end |
#bulk_search ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/foreman_tasks/api/tasks_controller.rb', line 76 def bulk_search searches = Array(params[:searches]) @tasks = {} ret = searches.map do |search_params| { search_params: search_params, results: search_tasks(search_params) } end render :json => ret end |
#callback ⇒ Object
170 171 172 173 174 175 176 |
# File 'app/controllers/foreman_tasks/api/tasks_controller.rb', line 170 def callback task = ForemanTasks::Task::DynflowTask.find(params[:callback][:task_id]) ForemanTasks.dynflow.world.event(task.external_id, params[:callback][:step_id].to_i, ::Actions::ProxyAction::CallbackData.new(params[:data])) render :json => { :message => 'processing' }.to_json end |
#index ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/controllers/foreman_tasks/api/tasks_controller.rb', line 133 def index scope =resource_scope.search_for(params[:search]).select('DISTINCT foreman_tasks_tasks.*') total = scope.count ordering_params = { sort_by: params[:sort_by] || 'started_at', sort_order: params[:sort_order] || 'DESC' } scope = ordering_scope(scope, ordering_params) pagination_params = { page: params[:page] || 1, per_page: params[:per_page] || 20 } scope = pagination_scope(scope, pagination_params) results = scope.map { |task| task_hash(task) } render :json => { total: total, subtotal: results.count, page: pagination_params[:page], per_page: pagination_params[:per_page], sort: { by: ordering_params[:sort_by], order: ordering_params[:sort_order] }, results: results } end |
#show ⇒ Object
41 42 |
# File 'app/controllers/foreman_tasks/api/tasks_controller.rb', line 41 def show end |
#summary ⇒ Object
35 36 37 |
# File 'app/controllers/foreman_tasks/api/tasks_controller.rb', line 35 def summary render :json => ForemanTasks::Task::Summarizer.new.summarize_by_status end |