mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-05 23:24:05 +08:00
Go: add context to redis client (#17689)
Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -520,7 +520,7 @@ func (h *AgentHandler) runWebhookDetached(
|
||||
zap.String("canvas", cv.ID),
|
||||
zap.Error(err))
|
||||
if isTest {
|
||||
appendWebhookTrace(cv.ID, startTs, canvas.RunEvent{Type: "error", SessionID: sessionID, Data: mustJSON(map[string]any{"message": err.Error()})})
|
||||
appendWebhookTrace(ctx, cv.ID, startTs, canvas.RunEvent{Type: "error", SessionID: sessionID, Data: mustJSON(map[string]any{"message": err.Error()})})
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -529,7 +529,7 @@ func (h *AgentHandler) runWebhookDetached(
|
||||
ev.SessionID = sessionID
|
||||
}
|
||||
if isTest {
|
||||
appendWebhookTrace(cv.ID, startTs, ev)
|
||||
appendWebhookTrace(ctx, cv.ID, startTs, ev)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -553,8 +553,8 @@ func (h *AgentHandler) runWebhookSync(
|
||||
events, err := h.loader.RunAgentWithWebhook(ctx, cv.UserID, cv.ID, payload)
|
||||
if err != nil {
|
||||
if isTest {
|
||||
appendWebhookTrace(cv.ID, startTs, canvas.RunEvent{Type: "error", SessionID: sessionID, Data: mustJSON(map[string]any{"message": err.Error()})})
|
||||
appendWebhookTrace(cv.ID, startTs, canvas.RunEvent{Type: "finished", SessionID: sessionID, Data: mustJSON(map[string]any{"success": false})})
|
||||
appendWebhookTrace(ctx, cv.ID, startTs, canvas.RunEvent{Type: "error", SessionID: sessionID, Data: mustJSON(map[string]any{"message": err.Error()})})
|
||||
appendWebhookTrace(ctx, cv.ID, startTs, canvas.RunEvent{Type: "finished", SessionID: sessionID, Data: mustJSON(map[string]any{"success": false})})
|
||||
}
|
||||
return webhookSyncResult{status: http.StatusBadRequest, body: gin.H{
|
||||
"code": 400,
|
||||
@@ -571,7 +571,7 @@ func (h *AgentHandler) runWebhookSync(
|
||||
ev.SessionID = sessionID
|
||||
}
|
||||
if isTest {
|
||||
appendWebhookTrace(cv.ID, startTs, ev)
|
||||
appendWebhookTrace(ctx, cv.ID, startTs, ev)
|
||||
}
|
||||
switch ev.Type {
|
||||
case "message":
|
||||
@@ -602,7 +602,7 @@ func (h *AgentHandler) runWebhookSync(
|
||||
}
|
||||
final := strings.Join(contents, "")
|
||||
if isTest {
|
||||
appendWebhookTrace(cv.ID, startTs, canvas.RunEvent{Type: "finished", SessionID: sessionID, Data: mustJSON(map[string]any{"success": true})})
|
||||
appendWebhookTrace(ctx, cv.ID, startTs, canvas.RunEvent{Type: "finished", SessionID: sessionID, Data: mustJSON(map[string]any{"success": true})})
|
||||
}
|
||||
return webhookSyncResult{status: status, body: gin.H{
|
||||
"message": final,
|
||||
@@ -629,14 +629,14 @@ func mustJSON(v any) string {
|
||||
// The trace key is `webhook-trace-<agent_id>-logs` with a 600 s TTL.
|
||||
// Each event is recorded as {"ts": <float>, "event": <type>, ...}.
|
||||
// Tests use miniredis to verify the key shape.
|
||||
func appendWebhookTrace(agentID string, startTs time.Time, ev canvas.RunEvent) {
|
||||
func appendWebhookTrace(ctx context.Context, agentID string, startTs time.Time, ev canvas.RunEvent) {
|
||||
rdb := rediscli.Get()
|
||||
if rdb == nil {
|
||||
return
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("webhook-trace-%s-logs", agentID)
|
||||
raw, _ := rdb.Get(key)
|
||||
raw, _ := rdb.Get(ctx, key)
|
||||
obj := map[string]any{}
|
||||
if raw != "" {
|
||||
_ = json.Unmarshal([]byte(raw), &obj)
|
||||
@@ -677,5 +677,5 @@ func appendWebhookTrace(agentID string, startTs time.Time, ev canvas.RunEvent) {
|
||||
common.Warn("webhook trace marshal failed", zap.Error(err))
|
||||
return
|
||||
}
|
||||
rdb.SetObj(key, string(encoded), 600*time.Second)
|
||||
rdb.SetObj(ctx, key, string(encoded), 600*time.Second)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user