-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
57 lines (47 loc) · 959 Bytes
/
server.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
48
49
50
51
52
53
54
55
56
57
package cron
import (
cron "github.com/robfig/cron/v3"
"log"
"os"
"os/signal"
)
type Server struct {
cron *cron.Cron
}
func NewServer() *Server {
return &Server{
cron: cron.New(cron.WithSeconds()),
}
}
func (s *Server) Start() {
s.cron.Run()
//t1 := time.NewTimer(time.Second * 10)
//for {
// select {
// case <-t1.C:
// t1.Reset(time.Second * 10)
// }
//}
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
<-quit
log.Println("Shutdown Cron ...")
}
func (s *Server) Stop() {
s.cron.Stop()
}
//Use Use
func (s *Server) Use() {
}
//AddFunc AddFunc
func (s *Server) AddFunc(spec string, cmd func()) {
addFunc, err := s.cron.AddFunc(spec, cmd)
if err != nil {
log.Fatalf("%+v", err)
return
}
log.Printf("task start.num:%+v", addFunc)
}
//RemoveFunc RemoveFunc
func (s *Server) RemoveFunc(name string) {
}