-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
47 lines (41 loc) · 1.36 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//go:generate bash -c "mkdir -p codegen && go run github.com/deepmap/oapi-codegen/cmd/[email protected] -generate types,server,spec -package codegen api/gocron/openapi.yaml > codegen/gocron_api.go"
/*
* @Author: [email protected] [email protected]
* @Date: 2022-10-21 11:47:53
* @LastEditors: [email protected] [email protected]
* @LastEditTime: 2022-11-29 15:22:15
* @FilePath: /gocron/main.go
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
package main
import (
"gocron/repository"
"gocron/route"
"gocron/service"
"log"
"net/http"
"time"
"github.com/robfig/cron/v3"
)
func init() {
// logger.LogInit()
repository.MyRepository = repository.NewRepository()
service.MyService = service.NewService(repository.MyRepository, cron.New(cron.WithSeconds()))
// 读取数据库的任务队列,重新加入cron.Addfunc
// 查询
// 再通过查询数据库初始化定时任务
service.MyService.Cron().GetCronByDB()
}
func main() {
r := route.InitV1Router()
srv := &http.Server{
Handler: r,
Addr: "0.0.0.0:8008",
// Good practice: enforce timeouts for servers you create!
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
log.Fatal(srv.ListenAndServe())
// c := cron.New(cron.WithSeconds())
// c.AddJob()
}