chore: import clean Agent Desk snapshot (3/7)
This commit is contained in:
54
internal/services/cronx/cron.go
Normal file
54
internal/services/cronx/cron.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package cronx
|
||||
|
||||
import (
|
||||
"agent-desk/internal/services"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
)
|
||||
|
||||
func Init() {
|
||||
c := cron.New()
|
||||
|
||||
addFunc(c, "0 4 ? * *", func() {
|
||||
fmt.Println("cron test")
|
||||
})
|
||||
|
||||
addFunc(c, "@every 30s", func() {
|
||||
if _, err := services.ConversationDispatchService.DispatchPendingConversations(0); err != nil {
|
||||
slog.Warn("dispatch pending conversations loop failed", "error", err)
|
||||
}
|
||||
})
|
||||
|
||||
addFunc(c, "@every 5s", func() {
|
||||
tgCount := services.TelegramOutboundService.DispatchPendingOutbox()
|
||||
if tgCount > 0 {
|
||||
slog.Info("telegram outbox dispatched", "count", tgCount)
|
||||
}
|
||||
zaloCount := services.ZaloOAOutboundService.DispatchPendingOutbox()
|
||||
if zaloCount > 0 {
|
||||
slog.Info("zalo oa outbox dispatched", "count", zaloCount)
|
||||
}
|
||||
slackCount := services.SlackOutboundService.DispatchPendingOutbox()
|
||||
if slackCount > 0 {
|
||||
slog.Info("slack outbox dispatched", "count", slackCount)
|
||||
}
|
||||
discordCount := services.DiscordOutboundService.DispatchPendingOutbox()
|
||||
if discordCount > 0 {
|
||||
slog.Info("discord outbox dispatched", "count", discordCount)
|
||||
}
|
||||
emailCount := services.EmailOutboundService.DispatchPendingOutbox()
|
||||
if emailCount > 0 {
|
||||
slog.Info("email outbox dispatched", "count", emailCount)
|
||||
}
|
||||
})
|
||||
|
||||
c.Start()
|
||||
}
|
||||
|
||||
func addFunc(c *cron.Cron, sepc string, cmd func()) {
|
||||
if _, err := c.AddFunc(sepc, cmd); err != nil {
|
||||
slog.Error("add cron func error", slog.Any("err", err))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user