-
Notifications
You must be signed in to change notification settings - Fork 0
/
infra_implemention.go
66 lines (57 loc) · 1.44 KB
/
infra_implemention.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
65
66
/*
* @Author: hongliu
* @Date: 2022-11-19 16:05:07
* @LastEditors: hongliu
* @LastEditTime: 2022-11-19 16:19:40
* @FilePath: \common\infra\job\infra_implemention.go
* @Description: 基础设施接口实现
*
* Copyright (c) 2022 by 洪流, All Rights Reserved.
*/
package job
import "context"
// 常量相关定义
const (
distributedJobInfraName string = "DistributedJob" // 分布式job基础设施名称
standaloneJobInfraName string = "StandaloneJob" // 单机式job基础设施名称
)
// Name 基础设施名称
func (i *DistributedJobInfra) Name() string {
return distributedJobInfraName
}
// start 基础设施启动
func (i *DistributedJobInfra) Start(ctx context.Context) error {
// 创建基础设施上下文对象与退出回调函数
i.ctx, i.cancel = context.WithCancel(ctx)
if i.cron != nil {
i.cron.Start()
}
return nil
}
// stop 停止基础设施
func (i *DistributedJobInfra) Stop() error {
if i.cron != nil {
i.cron.Stop()
}
return nil
}
// Name 基础设施名称
func (i *StandaloneJobInfra) Name() string {
return standaloneJobInfraName
}
// start 基础设施启动
func (i *StandaloneJobInfra) Start(ctx context.Context) error {
// 创建基础设施上下文对象与退出回调函数
i.ctx, i.cancel = context.WithCancel(ctx)
if i.cron != nil {
i.cron.Start()
}
return nil
}
// stop 停止基础设施
func (i *StandaloneJobInfra) Stop() error {
if i.cron != nil {
i.cron.Stop()
}
return nil
}