@@ -207,7 +207,12 @@ class DashboardController < ART::Controller
207207 n += 1
208208 end
209209 n.times do
210- installations << ch.receive
210+ select
211+ when x = ch.receive
212+ installations << x
213+ when timeout(5 .seconds)
214+ break
215+ end
211216 end
212217
213218 return ART ::StreamedResponse .new(headers: HTML_HEADERS ) do |io |
@@ -262,17 +267,39 @@ class DashboardController < ART::Controller
262267end
263268
264269private def get_latest_run (repo_owner : String , repo_name : String , workflow : String , branch : String , token : InstallationToken )
265- artifacts = begin
266- WorkflowRuns .for_workflow(repo_owner, repo_name, workflow, branch, token, max_items: 1 , expires_in: 5 .minutes)
267- rescue e : Halite ::Exception ::ClientError
268- if e.status_code.in?(401 , 404 )
269- raise ART ::Exceptions ::NotFound .new(" Repository '#{ repo_owner } /#{ repo_name } ' or workflow '#{ workflow } ' not found" )
270+ ch = Channel (Array (WorkflowRun ) | Exception ).new
271+ {% for event in [{" push" , 5 }, {" schedule" , 60 }] % }
272+ spawn do
273+ ch.send begin
274+ WorkflowRuns .for_workflow(repo_owner, repo_name, workflow, branch: branch, event: {{event[0 ]}}, token: token, max_items: 1 , expires_in: {{event[1 ]}}.minutes)
275+ rescue e
276+ if e.is_a?(Halite ::Exception ::ClientError ) && e.status_code.in?(401 , 404 )
277+ e = ART ::Exceptions ::NotFound .new(" Repository '#{ repo_owner } /#{ repo_name } ' or workflow '#{ workflow } ' not found" )
278+ end
279+ e
280+ end
270281 end
271- raise e
282+ {% end % }
283+
284+ runs = Array (WorkflowRun ).new
285+ exc = nil
286+ 2 .times do
287+ select
288+ when x = ch.receive
289+ case x
290+ in Exception
291+ exc ||= x
292+ in Array
293+ runs.concat(x)
294+ end
295+ when timeout(5 .seconds)
296+ break
297+ end
298+ end
299+ if runs.empty?
300+ raise exc || ART ::Exceptions ::NotFound .new(" No successful runs found for workflow '#{ workflow } ' and branch '#{ branch } '" )
272301 end
273- artifacts.find do |run |
274- run.event.in?(" push" , " schedule" )
275- end || raise ART ::Exceptions ::NotFound .new(" No successful runs found for workflow '#{ workflow } ' and branch '#{ branch } '" )
302+ runs.max_by & .updated_at
276303end
277304
278305class ArtifactsController < ART::Controller
0 commit comments