fix: wire retry into router, fix Docker config path, fix condition error handling, remove dead code

This commit is contained in:
2026-06-27 13:32:33 +08:00
parent 062014773c
commit 835b92ec00
3 changed files with 25 additions and 21 deletions
+18 -11
View File
@@ -1,6 +1,7 @@
package handler
import (
"context"
"encoding/json"
"io"
"log/slog"
@@ -63,15 +64,18 @@ func (h *NotifyHandler) Handle(c *gin.Context) {
// 4. Evaluate conditions
if rule.Conditions != nil {
var conds []model.Condition
if err := json.Unmarshal(*rule.Conditions, &conds); err == nil {
if !condition.Evaluate(conds, msg.Data) {
c.JSON(http.StatusOK, gin.H{
"matched": true,
"filtered": true,
"reason": "condition not met",
})
return
}
if err := json.Unmarshal(*rule.Conditions, &conds); err != nil {
slog.Error("failed to unmarshal rule conditions", "rule_id", rule.ID, "error", err)
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "invalid rule conditions"})
return
}
if !condition.Evaluate(conds, msg.Data) {
c.JSON(http.StatusOK, gin.H{
"matched": true,
"filtered": true,
"reason": "condition not met",
})
return
}
}
@@ -93,9 +97,10 @@ func (h *NotifyHandler) Handle(c *gin.Context) {
title := src.Name + ": " + msg.Event
channels := h.router.Route(c.Request.Context(), rule, title, content)
// 8. Log message (best effort)
// 8. Log message (best effort, detached context)
go func() {
payloadJSON, _ := json.Marshal(msg.Data)
ctx := context.Background()
for _, chName := range channels {
chID := parseChannelID(chName)
ml := &model.MessageLog{
@@ -107,7 +112,9 @@ func (h *NotifyHandler) Handle(c *gin.Context) {
Content: content,
Status: "pending",
}
_ = h.store.CreateMessageLog(c.Request.Context(), ml)
if err := h.store.CreateMessageLog(ctx, ml); err != nil {
slog.Warn("failed to create message log", "error", err)
}
}
}()