Skip to content

Commit

Permalink
Fix: shutdown by exiting scheduler with context (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpetrovic authored Oct 31, 2024
1 parent fb6fac1 commit 1e99cdc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
9 changes: 0 additions & 9 deletions cmd/gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package main

import (
"log"
"os"
"os/signal"
"syscall"

"github.com/beam-cloud/beta9/pkg/gateway"
)
Expand All @@ -15,12 +12,6 @@ func main() {
log.Fatalf("Error creating gateway service: %+v\n", err)
}

stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGTERM)

gw.Start()

<-stop

log.Println("Gateway stopped")
}
8 changes: 8 additions & 0 deletions pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ func (s *Scheduler) getControllers(request *types.ContainerRequest) ([]WorkerPoo

func (s *Scheduler) StartProcessingRequests() {
for {
select {
case <-s.ctx.Done():
// Context has been cancelled
return
default:
// Continue processing requests
}

if s.requestBacklog.Len() == 0 {
time.Sleep(requestProcessingInterval)
continue
Expand Down
1 change: 1 addition & 0 deletions pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func NewSchedulerForTest() (*Scheduler, error) {
}

return &Scheduler{
ctx: context.Background(),
eventBus: eventBus,
workerRepo: workerRepo,
workerPoolManager: workerPoolManager,
Expand Down

0 comments on commit 1e99cdc

Please sign in to comment.