init: hgmj server initial commit

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 16:50:13 +08:00
co-authored by Claude Opus 4.7
commit 625e89c15d
1870 changed files with 254090 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package job
import (
"context"
"time"
"91jd-server/common/log"
"github.com/robfig/cron/v3"
)
var statCron *cron.Cron
func init() {
statCron = cron.New(cron.WithSeconds()) //从秒开始的定时任务
}
// 开启定时任务
func Start() {
log.Info("start job...", log.Any("beginAt", time.Now()))
start()
}
func Stop() {
ctx := statCron.Stop()
<-ctx.Done()
err := ctx.Err()
//statCron.Stop()后,若job处于静默可能立即退出,再次执行<-ctx.Done()产生Canceled错误,此处忽略该错误
if err != nil && err != context.Canceled {
log.Error("Skd Job Stop error", log.E(err))
return
}
log.Info("end job", log.Any("endAt", time.Now()))
}