You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.3 KiB
Go

2 months ago
package icsbatch
import (
"fmt"
"log"
"mybatch/icsconf"
"mybatch/icslog"
2 months ago
stt "mybatch/icsstt"
"time"
2 months ago
"github.com/robfig/cron/v3"
)
var (
cfg icsconf.AppInfo
l *log.Logger
)
func init() {
cfg = icsconf.Getconfig()
l = icslog.InitializeLogger()
}
2 months ago
func BatchForPostRequestForDataList() {
loc, err := time.LoadLocation("Asia/Seoul")
if err != nil {
l.Fatalln("타임존 로드 실패: ", err)
}
2 months ago
cronInstance := cron.New(cron.WithLocation(loc))
// 매일 새벽 1시에 동작하는 크론인스턴스 추가
_, err = cronInstance.AddFunc("0 1 * * *", func() {
l.Println("calling ProcessPostRequestForDataList()")
2 months ago
stt.ProcessPostRequestForDataList()
})
if err != nil {
fmt.Println("스케줄 추가 오류:", err)
return
}
cronInstance.Start()
select {}
}
func BatchForPostRequestForDataListTest() {
loc, err := time.LoadLocation("Asia/Seoul")
if err != nil {
l.Fatalln("타임존 로드 실패: ", err)
}
2 months ago
cronInstance := cron.New(cron.WithLocation(loc))
_, err = cronInstance.AddFunc("51 12 * * *", func() {
l.Println("current server time: ", time.Now().Format("2006-01-02 15:04:05"))
fmt.Println("test succeeded")
2 months ago
})
if err != nil {
fmt.Println("스케줄 추가 오류:", err)
return
}
cronInstance.Start()
select {}
}