Process AI jobs concurrently
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"ai-service/internal/llm"
|
||||
@@ -94,6 +95,18 @@ func (w *Worker) tick(ctx context.Context) {
|
||||
slog.Error("claim jobs failed", "error", err)
|
||||
return
|
||||
}
|
||||
if len(jobs) > 1 {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(jobs))
|
||||
for _, job := range jobs {
|
||||
go func(job *model.Job) {
|
||||
defer wg.Done()
|
||||
w.process(ctx, job)
|
||||
}(job)
|
||||
}
|
||||
wg.Wait()
|
||||
return
|
||||
}
|
||||
for _, job := range jobs {
|
||||
w.process(ctx, job)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user