Class: TasksController

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

Instance Method Summary collapse

Instance Method Details

#clear_errorsObject



31
32
33
34
# File 'app/controllers/tasks_controller.rb', line 31

def clear_errors
  Task.error.destroy
  head :ok
end

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/tasks_controller.rb', line 7

def create
  @task = Task.new(task_params)

  if @task.save
    Metrics.new("tasks").count(
      task_id: @task.id,
      name: @task&.name,
      status: @task.status
    )

    render json: @task
  else
    render json: @task.errors, status: :unprocessable_entity
  end
end

#kill_containerObject



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

def kill_container
  KillTaskContainer.new(task: @task).perform

  head :ok
rescue KillTaskContainer::TaskNotRunningError => e
  render json: { message: e.message }, status: :bad_request
end

#logsObject



27
28
29
# File 'app/controllers/tasks_controller.rb', line 27

def logs
  render json: { logs: @task.get_logs&.encode("utf-8", undef: :replace, replace: "?") }
end

#mark_as_errorObject



36
37
38
39
40
41
42
43
44
# File 'app/controllers/tasks_controller.rb', line 36

def mark_as_error
  if @task.failed?
    @task.error!

    head :ok
  else
    render json: { message: "Task must have failed status to be marked as error" }, status: :unprocessable_entity
  end
end

#showObject



23
24
25
# File 'app/controllers/tasks_controller.rb', line 23

def show
  render json: @task
end