Sha256: 7a89e383134f9ba8913b3c9b32ca70dbacdec249190ae2e3b1396e5cb6e4db99

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true
module Shipit
  module Api
    class TasksController < BaseController
      require_permission :read, :stack
      require_permission :deploy, :stack, only: %i(trigger abort)

      def index
        render_resources(stack.tasks)
      end

      def show
        render_resource(task)
      end

      params do
        accepts :env, Hash, default: {}
      end
      def trigger
        render_resource(stack.trigger_task(params[:task_name], current_user, env: params.env), status: :accepted)
      rescue Shipit::Task::ConcurrentTaskRunning
        render(status: :conflict, json: {
          message: 'A task is already running.',
        })
      end

      def abort
        if task.active?
          task.abort!(aborted_by: current_user)
          head(:accepted)
        else
          render(status: :method_not_allowed, json: {
            message: "This task is not currently running.",
          })
        end
      end

      private

      def task
        stack.tasks.find(params[:id])
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shipit-engine-0.39.0 app/controllers/shipit/api/tasks_controller.rb
shipit-engine-0.38.0 app/controllers/shipit/api/tasks_controller.rb
shipit-engine-0.37.0 app/controllers/shipit/api/tasks_controller.rb
shipit-engine-0.36.1 app/controllers/shipit/api/tasks_controller.rb
shipit-engine-0.36.0 app/controllers/shipit/api/tasks_controller.rb