@@ -179,6 +179,7 @@ func NewOrchestratingBuilder(cfg Configuration) (res *Orchestrator, err error) {
179
179
gplayerHash : gplayerHash ,
180
180
buildListener : make (map [string ]map [buildListener ]struct {}),
181
181
logListener : make (map [string ]map [logListener ]struct {}),
182
+ runningBuilds : make (map [string ]* protocol.BuildInfo ),
182
183
censorship : make (map [string ][]string ),
183
184
builderAuthKey : builderAuthKey ,
184
185
}, nil
@@ -216,11 +217,13 @@ type Orchestrator struct {
216
217
gplayerHash string
217
218
wsman wsmanapi.WorkspaceManagerClient
218
219
219
- builderAuthKey [32 ]byte
220
- buildListener map [string ]map [buildListener ]struct {}
221
- logListener map [string ]map [logListener ]struct {}
222
- censorship map [string ][]string
223
- mu sync.RWMutex
220
+ builderAuthKey [32 ]byte
221
+ buildListener map [string ]map [buildListener ]struct {}
222
+ logListener map [string ]map [logListener ]struct {}
223
+ runningBuilds map [string ]* protocol.BuildInfo
224
+ runningBuildsMu sync.RWMutex
225
+ censorship map [string ][]string
226
+ mu sync.RWMutex
224
227
225
228
protocol.UnimplementedImageBuilderServer
226
229
}
@@ -426,8 +429,16 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
426
429
})
427
430
return
428
431
}, 1 * time .Second , 5 )
429
- if err != nil && status .Code (err ) != codes .AlreadyExists {
432
+ if status .Code (err ) == codes .AlreadyExists {
433
+ // build is already running - do not add it to the list of builds
434
+ } else if err != nil {
430
435
return status .Errorf (codes .Internal , "cannot start build: %q" , err )
436
+ } else {
437
+ o .runningBuilds [buildID ] = & protocol.BuildInfo {
438
+ Ref : wsrefstr ,
439
+ Status : protocol .BuildStatus_running ,
440
+ StartedAt : time .Now ().Unix (),
441
+ }
431
442
}
432
443
433
444
updates , cancel := o .registerBuildListener (buildID )
@@ -505,7 +516,7 @@ func (o *Orchestrator) ListBuilds(ctx context.Context, req *protocol.ListBuildsR
505
516
return & protocol.ListBuildsResponse {Builds : res }, nil
506
517
}
507
518
508
- func extractBuildStats (ws * wsmanapi.WorkspaceStatus ) * protocol.BuildInfo {
519
+ func extractBuildStatus (ws * wsmanapi.WorkspaceStatus ) * protocol.BuildInfo {
509
520
return & protocol.BuildInfo {
510
521
Ref : ws .Metadata .Annotations ["ref" ],
511
522
StartedAt : ws .Metadata .StartedAt .Seconds ,
@@ -514,21 +525,12 @@ func extractBuildStats(ws *wsmanapi.WorkspaceStatus) *protocol.BuildInfo {
514
525
}
515
526
516
527
func (o * Orchestrator ) getAllRunningBuilds (ctx context.Context ) (res []* protocol.BuildInfo , err error ) {
517
- span , ctx := opentracing .StartSpanFromContext (ctx , "getAllRunningBuilds" )
518
- defer tracing .FinishSpan (span , & err )
519
-
520
- wss , err := o .wsman .GetWorkspaces (ctx , & wsmanapi.GetWorkspacesRequest {
521
- MustMatch : & wsmanapi.MetadataFilter {
522
- Owner : buildWorkspaceOwnerID ,
523
- },
524
- })
525
- if err != nil {
526
- return
527
- }
528
+ o .runningBuildsMu .RLock ()
529
+ defer o .runningBuildsMu .RUnlock ()
528
530
529
- res = make ([]* protocol.BuildInfo , len (wss . Status ))
530
- for i , ws := range wss . Status {
531
- res [ i ] = extractBuildStats ( ws )
531
+ res = make ([]* protocol.BuildInfo , 0 , len (o . runningBuilds ))
532
+ for _ , ws := range o . runningBuilds {
533
+ res = append ( res , ws )
532
534
}
533
535
534
536
return
0 commit comments