Class: TasksController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- TasksController
- Defined in:
- app/controllers/tasks_controller.rb
Instance Method Summary collapse
- #clear_errors ⇒ Object
- #create ⇒ Object
- #kill_container ⇒ Object
- #logs ⇒ Object
- #mark_as_error ⇒ Object
- #show ⇒ Object
Instance Method Details
#clear_errors ⇒ Object
31 32 33 34 |
# File 'app/controllers/tasks_controller.rb', line 31 def clear_errors Task.error.destroy head :ok end |
#create ⇒ Object
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_container ⇒ Object
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. }, status: :bad_request end |
#logs ⇒ Object
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_error ⇒ Object
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 |
#show ⇒ Object
23 24 25 |
# File 'app/controllers/tasks_controller.rb', line 23 def show render json: @task end |