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
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 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,9 @@ install_python_requirements() {
fi
done
fi

echo "pre-import python modules..."
python3.10 -c "import llama_index.core;"
plutoless marked this conversation as resolved.
Show resolved Hide resolved
}

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