Resource Group API to list all upcoming jobs
Problem
When oldest_first
or newest_first
process mode is selected in a resource group, sometimes users need to know the upcoming jobs list to figure out which job is the current blocker. For example, #202186 (comment 690048551).
Users should be able to figure out which job is currently blocking the resource group.
Proposal
We add the following endpoint in Resource Group API:
GET /projects/:id/resource_groups/:key/upcoming_jobs
This returns the list of upcoming jobs to the resource group.
Implementation
It's easy to implement, as the following:
diff --git a/lib/api/ci/resource_groups.rb b/lib/api/ci/resource_groups.rb
index 02a5e92bd83..bb01381f268 100644
--- a/lib/api/ci/resource_groups.rb
+++ b/lib/api/ci/resource_groups.rb
@@ -3,6 +3,8 @@
module API
module Ci
class ResourceGroups < ::API::Base
+ include PaginationParams
+
before { authenticate! }
feature_category :continuous_delivery
@@ -41,6 +43,23 @@ class ResourceGroups < ::API::Base
render_validation_error!(resource_group)
end
end
+
+ desc 'List upcoming jobs of a resource group' do
+ success Entities::Ci::JobBasic
+ end
+ params do
+ requires :key, type: String, desc: 'The key of the resource group'
+ use :pagination
+ end
+ get ':id/resource_groups/:key/upcoming_jobs' do
+ authorize! :read_resource_group, resource_group
+ authorize! :read_build, user_project
+
+ upcoming_processables = resource_group.upcoming_processables
+ upcoming_processables = upcoming_processables.preload(:user, pipeline: :project)
+
+ present paginate(upcoming_processables), with: Entities::Ci::JobBasic
+ end
end
helpers do