diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /app/graphql/types/ci/runner_type.rb | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'app/graphql/types/ci/runner_type.rb')
-rw-r--r-- | app/graphql/types/ci/runner_type.rb | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/app/graphql/types/ci/runner_type.rb b/app/graphql/types/ci/runner_type.rb index 837d91ef765..9c5041b0860 100644 --- a/app/graphql/types/ci/runner_type.rb +++ b/app/graphql/types/ci/runner_type.rb @@ -6,6 +6,10 @@ module Types graphql_name 'CiRunner' authorize :read_runner + JOB_COUNT_LIMIT = 1000 + + alias_method :runner, :object + field :id, ::Types::GlobalIDType[::Ci::Runner], null: false, description: 'ID of the runner.' field :description, GraphQL::STRING_TYPE, null: true, @@ -21,22 +25,48 @@ module Types description: 'Indicates the runner is allowed to receive jobs.' field :status, ::Types::Ci::RunnerStatusEnum, null: false, description: 'Status of the runner.' - field :version, GraphQL::STRING_TYPE, null: false, + field :version, GraphQL::STRING_TYPE, null: true, description: 'Version of the runner.' field :short_sha, GraphQL::STRING_TYPE, null: true, description: %q(First eight characters of the runner's token used to authenticate new job requests. Used as the runner's unique ID.) - field :revision, GraphQL::STRING_TYPE, null: false, + field :revision, GraphQL::STRING_TYPE, null: true, description: 'Revision of the runner.' field :locked, GraphQL::BOOLEAN_TYPE, null: true, description: 'Indicates the runner is locked.' field :run_untagged, GraphQL::BOOLEAN_TYPE, null: false, description: 'Indicates the runner is able to run untagged jobs.' - field :ip_address, GraphQL::STRING_TYPE, null: false, + field :ip_address, GraphQL::STRING_TYPE, null: true, description: 'IP address of the runner.' field :runner_type, ::Types::Ci::RunnerTypeEnum, null: false, description: 'Type of the runner.' field :tag_list, [GraphQL::STRING_TYPE], null: true, description: 'Tags associated with the runner.' + field :project_count, GraphQL::INT_TYPE, null: true, + description: 'Number of projects that the runner is associated with.' + field :job_count, GraphQL::INT_TYPE, null: true, + description: "Number of jobs processed by the runner (limited to #{JOB_COUNT_LIMIT}, plus one to indicate that more items exist)." + + def job_count + # We limit to 1 above the JOB_COUNT_LIMIT to indicate that more items exist after JOB_COUNT_LIMIT + runner.builds.limit(JOB_COUNT_LIMIT + 1).count + end + + # rubocop: disable CodeReuse/ActiveRecord + def project_count + BatchLoader::GraphQL.for(runner.id).batch(key: :runner_project_count) do |ids, loader, args| + counts = ::Ci::Runner.project_type + .select(:id, 'COUNT(ci_runner_projects.id) as count') + .left_outer_joins(:runner_projects) + .where(id: ids) + .group(:id) + .index_by(&:id) + + ids.each do |id| + loader.call(id, counts[id]&.count) + end + end + end + # rubocop: enable CodeReuse/ActiveRecord end end end |