Class: ForemanInventoryUpload::Api::TasksController
- Inherits:
-
Api::V2::BaseController
- Object
- Api::V2::BaseController
- ForemanInventoryUpload::Api::TasksController
- Defined in:
- app/controllers/foreman_inventory_upload/api/tasks_controller.rb
Constant Summary collapse
- ACTION_TYPES =
[ 'ForemanInventoryUpload::Async::HostInventoryReportJob', 'ForemanInventoryUpload::Async::UploadReportDirectJob', ].freeze
Instance Method Summary collapse
-
#current ⇒ Object
GET /foreman_inventory_upload/api/tasks/current Returns current running/active tasks for inventory operations.
-
#history ⇒ Object
GET /foreman_inventory_upload/api/tasks/history Returns recent task history for inventory operations.
Instance Method Details
#current ⇒ Object
GET /foreman_inventory_upload/api/tasks/current Returns current running/active tasks for inventory operations
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/foreman_inventory_upload/api/tasks_controller.rb', line 11 def current organization_id = validate_organization_id if params[:organization_id].present? return if performed? tasks = ForemanTasks::Task .active .for_action_types(ACTION_TYPES) .with_duration if organization_id.present? tasks = tasks.joins(:links) .where(foreman_tasks_links: { resource_type: 'Organization', resource_id: organization_id, }) end render json: { tasks: tasks.map { |task| task_json(task) }, } end |
#history ⇒ Object
GET /foreman_inventory_upload/api/tasks/history Returns recent task history for inventory operations
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/foreman_inventory_upload/api/tasks_controller.rb', line 35 def history organization_id = validate_organization_id if params[:organization_id].present? return if performed? limit = validated_limit tasks = ForemanTasks::Task .for_action_types(ACTION_TYPES) .with_duration .order('started_at DESC') .limit(limit) if organization_id.present? tasks = tasks.joins(:links) .where(foreman_tasks_links: { resource_type: 'Organization', resource_id: organization_id, }) end render json: { tasks: tasks.map { |task| task_json(task) }, } end |