Class: StatusController

Inherits:
ApplicationController show all
Defined in:
app/controllers/status_controller.rb

Constant Summary collapse

LIMIT_TASKS =
200

Instance Method Summary collapse

Instance Method Details

#nodesObject



6
7
8
# File 'app/controllers/status_controller.rb', line 6

def nodes
  render json: Node.includes(:slots).order(name: :asc), each_serializer: StatusPanelNodeSerializer
end

#retry_taskObject



44
45
46
47
48
49
# File 'app/controllers/status_controller.rb', line 44

def retry_task
  @task = Task.find_by!(uuid: params[:uuid])
  @task.force_retry!

  head :ok
end

#tag_valuesObject



39
40
41
42
# File 'app/controllers/status_controller.rb', line 39

def tag_values
  @tag = TaskTag.find_by!(name: params[:tag_name])
  render json: @tag.values.take(50)
end

#tagsObject



30
31
32
33
# File 'app/controllers/status_controller.rb', line 30

def tags
  @tags = TaskTag.pluck(:name)
  render json: @tags
end

#task_statusesObject



35
36
37
# File 'app/controllers/status_controller.rb', line 35

def task_statuses
  render json: Task.all_status
end

#tasksObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/status_controller.rb', line 10

def tasks
  limit = params.fetch(:limit, LIMIT_TASKS).to_i

  @tasks = Task
           .only(Task.attribute_names - %w[logs])
           .includes(:slot)
           .order_by("created_at" => "desc")
           .batch_size(limit)
           .limit(limit)

  @tasks = @tasks.where(status: params[:status]) if params[:status].present?
  if params[:tags]
    params.require(:tags).each do |tag, value|
      @tasks = @tasks.where("tags.#{tag}" => value.to_s)
    end
  end

  render json: @tasks, each_serializer: StatusPanelTaskSerializer
end