Skip to content

Commit

Permalink
1. pre-import llama-index package (#247)
Browse files Browse the repository at this point in the history
* 1. pre-import llama-index package
2. ensure all processes are killed when SIG_TERM is received

* feat: added comments for pre-import
  • Loading branch information
plutoless authored Aug 24, 2024
1 parent 68afa67 commit 03a7800
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions agents/scripts/install_deps_and_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ install_python_requirements() {
fi
done
fi

# pre-import llama-index as it cloud download additional resources during the first import
echo "pre-import python modules..."
python3.10 -c "import llama_index.core;"
}

build_go_app() {
Expand Down
2 changes: 1 addition & 1 deletion server/internal/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,6 @@ func (s *HttpServer) Start() {

slog.Info("server start", "port", s.config.Port, logTag)

go cleanWorker()
go timeoutWorkers()
r.Run(fmt.Sprintf(":%s", s.config.Port))
}
14 changes: 13 additions & 1 deletion server/internal/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (w *Worker) update(req *WorkerUpdateReq) (err error) {
return
}

func cleanWorker() {
func timeoutWorkers() {
for {
for _, channelName := range workers.Keys() {
worker := workers.Get(channelName).(*Worker)
Expand All @@ -248,3 +248,15 @@ func cleanWorker() {
time.Sleep(workerCleanSleepSeconds * time.Second)
}
}

func CleanWorkers() {
for _, channelName := range workers.Keys() {
worker := workers.Get(channelName).(*Worker)
if err := worker.stop(uuid.New().String(), channelName.(string)); err != nil {
slog.Error("Worker cleanWorker failed", "err", err, "channelName", channelName, logTag)
continue
}

slog.Info("Worker cleanWorker success", "channelName", channelName, "worker", worker, logTag)
}
}
14 changes: 14 additions & 0 deletions server/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package main

import (
"fmt"
"log/slog"
"os"
"os/signal"
"strconv"
"syscall"

"github.com/joho/godotenv"

Expand Down Expand Up @@ -51,6 +54,17 @@ func main() {
os.Exit(1)
}

// Set up signal handler to clean up all workers on Ctrl+C
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

go func() {
<-sigs
fmt.Println("Received interrupt signal, cleaning up workers...")
internal.CleanWorkers()
os.Exit(0)
}()

// Start server
httpServerConfig := &internal.HttpServerConfig{
AppId: agoraAppId,
Expand Down

0 comments on commit 03a7800

Please sign in to comment.