@@ -8,7 +8,8 @@ module Limit
8
8
max : 'max jobs for %s by %s: %s' ,
9
9
max_plan : 'max jobs for %s by %s: %s (%s)' ,
10
10
max_stage : 'jobs for %s limited at stage: %s (queueable: %s)' ,
11
- summary : '%s: total: %s, running: %s, queueable: %s'
11
+ summary : '%s: total: %s, running: %s, queueable: %s' ,
12
+ stats : 'jobs waiting for %s: %s'
12
13
}
13
14
14
15
class Jobs < Struct . new ( :context , :owners )
@@ -26,6 +27,7 @@ def run
26
27
unleak_queueables if ENV [ 'UNLEAK_QUEUEABLE_JOBS' ]
27
28
check_all
28
29
report summary
30
+ report stats if waiting . any?
29
31
end
30
32
31
33
def reports
@@ -77,11 +79,7 @@ def check(job)
77
79
end
78
80
79
81
def enqueue? ( job )
80
- limits_for ( job ) . map do |limit |
81
- result = limit . enqueue?
82
- # report *limit.reports
83
- result
84
- end . inject ( &:& )
82
+ limits_for ( job ) . map ( &:enqueue? ) . inject ( &:& )
85
83
end
86
84
87
85
def limits_for ( job )
@@ -92,10 +90,20 @@ def summary
92
90
MSGS [ :summary ] % [ owners . to_s , queueable . size , state . running_by_owners , selected . size ]
93
91
end
94
92
93
+ def stats
94
+ jobs = waiting . group_by ( &:repository )
95
+ stats = jobs . map { |repo , jobs | [ repo . slug , jobs . size ] . join ( '=' ) }
96
+ MSGS [ :stats ] % [ owners . key , stats . join ( ', ' ) ]
97
+ end
98
+
95
99
def report ( *reports )
96
100
self . reports . concat ( reports ) . uniq!
97
101
end
98
102
103
+ def waiting
104
+ queueable - selected
105
+ end
106
+
99
107
def queueable
100
108
@queueable ||= Job . by_owners ( owners . all ) . queueable . to_a
101
109
end
0 commit comments