54 lines
1.2 KiB
Go
Raw Normal View History

2025-06-04 09:51:39 +08:00
package monitor
import (
"fmt"
"github.com/wanghuiyt/ding"
"samba/pkg/ksync"
"samba/pkg/log"
"samba/pkg/task"
"samba/server/other/handler"
"strings"
"time"
)
type Ding struct {
*ding.Webhook
sendDing bool
}
func (d *Ding) SendMessageText(text string, at ...string) error {
log.Debug(fmt.Sprintf("发送钉钉消息:%s", text))
if !d.sendDing {
return nil
}
return d.Webhook.SendMessageText(text, at...)
}
func (d *Ding) Apply(t *task.Task) {
branch, _ := handler.GetEnv[string]("GitBranch")
if strings.Contains(strings.ToLower(branch), "release") {
d.sendDing = true
}
if !d.sendDing {
log.Debug(fmt.Sprintf("Task:%s 非release版本不发送至钉钉", t.Name()))
}
d.Webhook = &ding.Webhook{
AccessToken: ksync.DingAccessToken,
Secret: ksync.DingSecret,
}
}
type TestTicker struct {
}
func (*TestTicker) Apply(t *task.Task) {
// FIXME for test
ksync.DingAccessToken = "e20c2217ae056af5d574d7a5c01340ce5d72eb77ae4ff05974e8c72f3a6b1ca2"
ksync.DingSecret = "SECfc662dd07db57dea77bd2e44798cb88d89fec9c6ced8207408fd9d7c1f377dfb"
log.Debug(fmt.Sprintf("任务 %s 测试ticker为10秒", t.Name()))
t.Ticker(10 * time.Second).Fixed()
}