fix: 1.增加env配置 2.增加任务后门
This commit is contained in:
parent
847eb8b5db
commit
7e71ad52a4
|
|
@ -13,6 +13,7 @@ func main() {
|
||||||
configPath := flag.String("config", "./config/config_test.yaml", "Path to configuration file")
|
configPath := flag.String("config", "./config/config_test.yaml", "Path to configuration file")
|
||||||
onBot := flag.String("bot", "", "bot start")
|
onBot := flag.String("bot", "", "bot start")
|
||||||
cron := flag.String("cron", "", "close")
|
cron := flag.String("cron", "", "close")
|
||||||
|
runJob := flag.String("runJob", "", "run single job and exit")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
bc, err := config.LoadConfig(*configPath)
|
bc, err := config.LoadConfig(*configPath)
|
||||||
|
|
@ -33,6 +34,11 @@ func main() {
|
||||||
if *cron == "start" {
|
if *cron == "start" {
|
||||||
app.Cron.Run(ctx)
|
app.Cron.Run(ctx)
|
||||||
}
|
}
|
||||||
|
// 运行指定任务并退出
|
||||||
|
if *runJob != "" {
|
||||||
|
app.Cron.RunOnce(ctx, *runJob)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
log.Fatal(app.HttpServer.Listen(fmt.Sprintf(":%d", bc.Server.Port)))
|
log.Fatal(app.HttpServer.Listen(fmt.Sprintf(":%d", bc.Server.Port)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,22 @@ tools:
|
||||||
zltxOrderAfterSaleResellerBatch:
|
zltxOrderAfterSaleResellerBatch:
|
||||||
enabled: true
|
enabled: true
|
||||||
base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/afterSales/reseller_pre_ai"
|
base_url: "https://gateway.dev.cdlsxd.cn/zltx_api/admin/afterSales/reseller_pre_ai"
|
||||||
|
weather:
|
||||||
|
enabled: true
|
||||||
|
base_url: "https://restapi.amap.com/v3/weather/weatherInfo"
|
||||||
|
api_key: "12afbde5ab78cb7e575ff76bd0bdef2b"
|
||||||
|
cozeExpress:
|
||||||
|
enabled: true
|
||||||
|
base_url: "https://api.coze.cn"
|
||||||
|
api_key: "7582477438102552616"
|
||||||
|
api_secret: "pat_eEN0BdLNDughEtABjJJRYTW71olvDU0qUbfQUeaPc2NnYWO8HeyNoui5aR9z0sSZ"
|
||||||
|
cozeCompany:
|
||||||
|
enabled: true
|
||||||
|
base_url: "https://api.coze.cn"
|
||||||
|
api_key: "7583905168607100978"
|
||||||
|
api_secret: "pat_eEN0BdLNDughEtABjJJRYTW71olvDU0qUbfQUeaPc2NnYWO8HeyNoui5aR9z0sSZ"
|
||||||
|
zltxResellerAuthProductToManagerAndDefaultLossReason:
|
||||||
|
base_url: "https://revcl.1688sup.com/api/admin/reseller/resellerAuthProduct/getManagerAndDefaultLossReason"
|
||||||
# eino tool 配置
|
# eino tool 配置
|
||||||
eino_tools:
|
eino_tools:
|
||||||
# == 货易通 hyt ==
|
# == 货易通 hyt ==
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package server
|
||||||
import (
|
import (
|
||||||
"ai_scheduler/internal/services"
|
"ai_scheduler/internal/services"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2/log"
|
"github.com/gofiber/fiber/v2/log"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
|
|
@ -20,6 +21,7 @@ type cronJob struct {
|
||||||
EntryId int32
|
EntryId int32
|
||||||
Func func(context.Context) error
|
Func func(context.Context) error
|
||||||
Name string
|
Name string
|
||||||
|
Key string
|
||||||
Schedule string
|
Schedule string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,11 +44,13 @@ func (c *CronServer) InitJobs(ctx context.Context) {
|
||||||
{
|
{
|
||||||
Func: c.cronService.CronReportSendDingTalk,
|
Func: c.cronService.CronReportSendDingTalk,
|
||||||
Name: "直连天下报表推送(钉钉)",
|
Name: "直连天下报表推送(钉钉)",
|
||||||
|
Key: "ding_report_dingtalk",
|
||||||
Schedule: "20 12,18,23 * * *",
|
Schedule: "20 12,18,23 * * *",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Func: c.cronService.CronReportSendQywx,
|
Func: c.cronService.CronReportSendQywx,
|
||||||
Name: "直连天下报表推送(微信)",
|
Name: "直连天下报表推送(微信)",
|
||||||
|
Key: "ding_report_qywx",
|
||||||
Schedule: "20 12,18,23 * * *",
|
Schedule: "20 12,18,23 * * *",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -96,3 +100,39 @@ func (c *CronServer) Stop() {
|
||||||
c.log.Info("Cron调度器已停止")
|
c.log.Info("Cron调度器已停止")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CronServer) RunOnce(ctx context.Context, key string) error {
|
||||||
|
|
||||||
|
if c.jobs == nil {
|
||||||
|
c.InitJobs(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取key对应的任务
|
||||||
|
var job *cronJob
|
||||||
|
for _, j := range c.jobs {
|
||||||
|
if j.Key == key {
|
||||||
|
job = j
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if job == nil {
|
||||||
|
return fmt.Errorf("unknown job key: %s\n", key)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
fmt.Printf("任务[once]:%s执行时发生panic: %v\n", job.Name, r)
|
||||||
|
}
|
||||||
|
fmt.Printf("任务[once]:%s执行结束\n", job.Name)
|
||||||
|
}()
|
||||||
|
|
||||||
|
fmt.Printf("任务[once]:%s开始执行\n", job.Name)
|
||||||
|
|
||||||
|
err := job.Func(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("任务[once]:%s执行失败: %s\n", job.Name, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("任务[once]:%s执行成功\n", job.Name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue