Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1. pre-import llama-index package #247

Merged
merged 2 commits into from
Aug 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions agents/scripts/install_deps_and_build.sh
Original file line number Diff line number Diff line change
@@ -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() {
2 changes: 1 addition & 1 deletion server/internal/http_server.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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)
@@ -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"

@@ -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,