CloseAndRecv in send
All checks were successful
/ Make image (push) Successful in 49s

This commit is contained in:
nquidox 2026-03-01 01:01:06 +03:00
parent 77c626a7c3
commit a32b1ef69b
3 changed files with 15 additions and 6 deletions

View file

@ -141,7 +141,7 @@ func (app *App) Run(ctx context.Context) {
l := len(sendData)
if l > 0 {
log.WithField("length", l).Debug("Sending parsed data")
app.network.SendResult(apiClient, sendData)
app.network.SendResult(ctx, apiClient, sendData)
sendData = sendData[:0]
}
}

View file

@ -8,5 +8,5 @@ import (
type Handler interface {
RequestTasks(ctx context.Context, client pb.TaskProcessorClient) []shared.TaskResponse
SendResult(client pb.TaskProcessorClient, tasksDone []shared.TaskResult)
SendResult(ctx context.Context, client pb.TaskProcessorClient, tasksDone []shared.TaskResult)
}

View file

@ -5,10 +5,14 @@ import (
log "github.com/sirupsen/logrus"
"task-processor/internal/shared"
pb "task-processor/proto/taskProcessor"
"time"
)
func (n *Network) SendResult(client pb.TaskProcessorClient, tasksDone []shared.TaskResult) {
stream, err := client.SendResult(context.Background())
func (n *Network) SendResult(ctx context.Context, client pb.TaskProcessorClient, tasksDone []shared.TaskResult) {
sendCtx, cancel := context.WithTimeout(ctx, time.Second*60)
defer cancel()
stream, err := client.SendResult(sendCtx)
if err != nil {
log.Fatalf("Error calling PostMerch: %v", err)
}
@ -29,7 +33,12 @@ func (n *Network) SendResult(client pb.TaskProcessorClient, tasksDone []shared.T
}
}
if err = stream.CloseSend(); err != nil {
log.Fatalf("Error closing stream: %v", err)
//if err = stream.CloseSend(); err != nil {
// log.Fatalf("Error closing stream: %v", err)
//}
_, err = stream.CloseAndRecv()
if err != nil {
log.Fatalf("Error receiving response: %v", err)
}
}