6816289552
build / build (push) Successful in 1m23s
周报页新增自动发送区:管理员配置 SMTP/收件人/发送星期与小时,授权码用主密钥加密保存。 确认绑定当前草稿版本与正文哈希,正文再改则确认失效;worker 每分钟仅在启用、到点、周已结束且未发送过时发一次。 邮件同时提供渲染后的 HTML 与可读纯文本;SMTP 仅允许 TLS,拒绝明文。 迁移 000060 新增设置、确认与发送记录三张表,唯一键防重复发送。
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"knowledge-governance/internal/qawemail"
|
|
)
|
|
|
|
// weeklyMailLoop sends the confirmed weekly report exactly inside the configured slot.
|
|
// It runs in the ordinary worker so the console never depends on a browser staying open.
|
|
func weeklyMailLoop(ctx context.Context, pool *pgxpool.Pool, getenv func(string) string) {
|
|
tenant := getenv("DOBOTAI_OPS_TENANT_KEY")
|
|
if tenant == "" {
|
|
log.Print("weekly mail disabled: tenant key not configured")
|
|
return
|
|
}
|
|
store := qawemail.NewStore(pool, tenant, getenv("QA_AI_MASTER_KEY_FILE"), nil)
|
|
ticker := time.NewTicker(time.Minute)
|
|
defer ticker.Stop()
|
|
lastState := ""
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
runCtx, cancel := context.WithTimeout(ctx, 90*time.Second)
|
|
result, err := store.SendDue(runCtx, time.Now())
|
|
cancel()
|
|
if err != nil {
|
|
log.Printf("weekly mail attempt failed: %v", err)
|
|
continue
|
|
}
|
|
if result.State != lastState {
|
|
lastState = result.State
|
|
log.Printf("weekly mail state=%s week=%s reason=%s", result.State, result.Week, result.Reason)
|
|
}
|
|
}
|
|
}
|
|
}
|