forked from farseer-go/fSchedule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.go
64 lines (53 loc) · 1.56 KB
/
module.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
58
59
60
61
62
63
64
package fSchedule
import (
"fmt"
"github.com/farseer-go/fs"
"github.com/farseer-go/fs/configure"
"github.com/farseer-go/fs/container"
"github.com/farseer-go/fs/core"
"github.com/farseer-go/fs/flog"
"github.com/farseer-go/fs/modules"
"github.com/farseer-go/fs/timingWheel"
"github.com/farseer-go/webapi"
)
type Module struct {
}
func (module Module) DependsModule() []modules.FarseerModule {
return []modules.FarseerModule{webapi.Module{}}
}
func (module Module) PreInitialize() {
// 服务端配置
defaultServer = serverVO{
Address: configure.GetSlice("FSchedule.Server.Address"),
Token: configure.GetString("FSchedule.Server.Token"),
}
// 客户端配置
NewClient()
timingWheel.Start()
// 初始化日志队列
logQueue = make(chan logContent, 2048)
}
func (module Module) PostInitialize() {
// 调试状态下,不开启与调度中心的通信
if configure.GetBool("FSchedule.Debug.Enable") {
flog.Warning("FSchedule当前为调试状态,将模拟调用任务")
return
}
webapi.Area("/api/", func() {
webapi.RegisterPOST("/check", Check)
webapi.RegisterPOST("/invoke", Invoke)
webapi.RegisterPOST("/status", Status)
webapi.RegisterPOST("/kill", Kill)
})
webapi.UseApiResponse()
webapi.UsePprof()
go webapi.Run(fmt.Sprintf("%s:%d", defaultClient.ClientIp, defaultClient.ClientPort))
fs.AddInitCallback("开启上传调度中心日志", func() {
go enableReportLog()
})
// 注册健康检查
container.RegisterInstance[core.IHealthCheck](&healthCheck{}, "fSchedule")
}
func (module Module) Shutdown() {
defaultClient.LogoutClient()
}