Class: ForemanTasks::TasksController

Inherits:
ApplicationController
  • Object
show all
Includes:
Foreman::Controller::AutoCompleteSearch, Foreman::Controller::CsvResponder, FindTasksCommon
Defined in:
app/controllers/foreman_tasks/tasks_controller.rb

Instance Method Summary collapse

Methods included from FindTasksCommon

#current_taxonomy_search, #search_query

Instance Method Details

#abortObject



47
48
49
50
51
52
53
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 47

def abort
  if @dynflow_task.abort
    render json: { statusText: 'OK' }
  else
    render json: {}, status: :bad_request
  end
end

#cancelObject



39
40
41
42
43
44
45
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 39

def cancel
  if @dynflow_task.cancel
    render json: { statusText: 'OK' }
  else
    render json: {}, status: :bad_request
  end
end

#cancel_stepObject



30
31
32
33
34
35
36
37
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 30

def cancel_step
  result = ForemanTasks.dynflow.world.event(@dynflow_task.external_id, params[:step_id].to_i, ::Dynflow::Action::Cancellable::Cancel).wait
  if result.rejected?
    render json: { error: result.reason }, status: :bad_request
  else
    render json: { statusText: 'OK' }
  end
end

#controller_nameObject

we need do this to make the Foreman helpers working properly



84
85
86
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 84

def controller_name
  'foreman_tasks_tasks'
end

#force_unlockObject



73
74
75
76
77
78
79
80
81
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 73

def force_unlock
  if @dynflow_task.pending?
    @dynflow_task.halt
    render json: { statusText: 'OK' }
  else
    # Cannot halt an already stopped task
    render json: {}, status: :bad_request
  end
end

#indexObject



9
10
11
12
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 9

def index
  params[:order] ||= 'started_at DESC'
  respond_with_tasks resource_base
end

#resource_classObject



88
89
90
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 88

def resource_class
  ForemanTasks::Task
end

#resumeObject



55
56
57
58
59
60
61
62
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 55

def resume
  if @dynflow_task.resumable?
    ForemanTasks.dynflow.world.execute(@dynflow_task.execution_plan.id)
    render json: { statusText: 'OK' }
  else
    render json: {}, status: :bad_request
  end
end

#sub_tasksObject



24
25
26
27
28
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 24

def sub_tasks
  # @task is used when rendering breadcrumbs
  @task = resource_base.find(params[:id])
  respond_with_tasks @task.sub_tasks
end

#summaryObject



14
15
16
17
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 14

def summary
  scope = resource_base.search_for(current_taxonomy_search).select(:id)
  render json: Task::Summarizer.new(Task.where(:id => scope), params[:recent_timeframe].to_i).summary
end

#summary_sub_tasksObject



19
20
21
22
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 19

def summary_sub_tasks
  filtered_scope = resource_base.find(params[:id]).sub_tasks
  render :json => Task::Summarizer.new(filtered_scope, params[:recent_timeframe].to_i).summary
end

#unlockObject



64
65
66
67
68
69
70
71
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 64

def unlock
  if @dynflow_task.paused?
    @dynflow_task.halt
    render json: { statusText: 'OK' }
  else
    render json: {}, status: :bad_request
  end
end