Sha256: e294c25e76a3600db89589b394b4ca397545825258bdf6392e18df72d9e6765f

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

module ForemanInventoryUpload
  class TasksController < ::ApplicationController
    def create
      selected_org = Organization.current
      subscribed_hosts_ids = Set.new(
        ForemanInventoryUpload::Generators::Queries.for_slice(
          Host.unscoped.where(organization: selected_org)
        ).pluck(:id)
      )

      if subscribed_hosts_ids.empty?
        return render json: {
          message: N_('Nothing to sync, there are no hosts with subscription for this organization.'),
        }, status: :method_not_allowed
      else
        task = ForemanTasks.async_task(InventorySync::Async::InventoryFullSync, selected_org)
      end
      return render json: { message: N_('there was an issue triggering the task') }, status: :internal_server_error unless task

      render json: {
        task: task,
      }, status: :ok
    end

    def show
      task = ForemanTasks::Task.find_by(id: params[:id])
      return render json: { message: N_('No task was found') }, status: :internal_server_error unless task

      render json: {
        endedAt: task.ended_at,
        output: task.output,
        result: task.result,
      }, status: :ok
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foreman_rh_cloud-3.0.22 app/controllers/foreman_inventory_upload/tasks_controller.rb
foreman_rh_cloud-4.0.22 app/controllers/foreman_inventory_upload/tasks_controller.rb
foreman_rh_cloud-4.0.21.1 app/controllers/foreman_inventory_upload/tasks_controller.rb
foreman_rh_cloud-3.0.21.1 app/controllers/foreman_inventory_upload/tasks_controller.rb
foreman_rh_cloud-3.0.21 app/controllers/foreman_inventory_upload/tasks_controller.rb
foreman_rh_cloud-3.0.20 app/controllers/foreman_inventory_upload/tasks_controller.rb
foreman_rh_cloud-3.0.19 app/controllers/foreman_inventory_upload/tasks_controller.rb