|
|
|
@ -13,13 +13,14 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type JobsGormConfig struct {
|
|
|
|
|
GormClient *dorm.GormClient // 数据库驱动
|
|
|
|
|
RedisClient *dorm.RedisClient // 缓存数据库驱动
|
|
|
|
|
CurrentIp string // 当前ip
|
|
|
|
|
LockPrefix string // 锁Key前缀 xxx_lock
|
|
|
|
|
LockSeparator string // 锁分隔符 xxx_lock
|
|
|
|
|
CornPrefix string // 任务前缀 xxx_cron
|
|
|
|
|
Debug bool // 调试
|
|
|
|
|
GormClient *dorm.GormClient // 数据库驱动
|
|
|
|
|
RedisClient *dorm.RedisClient // 缓存数据库驱动
|
|
|
|
|
CurrentIp string // 当前ip
|
|
|
|
|
LockKeyPrefix string // 锁Key前缀 xxx_lock
|
|
|
|
|
LockKeySeparator string // 锁Key分隔符 :
|
|
|
|
|
CornKeyPrefix string // 任务Key前缀 xxx_cron
|
|
|
|
|
CornKeyCustom string // 任务Key自定义 xxx_cron_自定义 xxx_cron_自定义_*
|
|
|
|
|
Debug bool // 调试
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// JobsGorm Gorm数据库驱动
|
|
|
|
@ -28,21 +29,19 @@ type JobsGorm struct {
|
|
|
|
|
redisClient *dorm.RedisClient // 缓存驱动
|
|
|
|
|
lockClient *golock.LockRedis // 锁驱动
|
|
|
|
|
config struct {
|
|
|
|
|
debug bool // 调试
|
|
|
|
|
runVersion string // 运行版本
|
|
|
|
|
os string // 系统类型
|
|
|
|
|
arch string // 系统架构
|
|
|
|
|
maxProCs int // CPU核数
|
|
|
|
|
version string // GO版本
|
|
|
|
|
macAddrS string // Mac地址
|
|
|
|
|
insideIp string // 内网ip
|
|
|
|
|
outsideIp string // 外网ip
|
|
|
|
|
lockPrefix string // 锁Key前缀
|
|
|
|
|
lockSeparator string // 锁分隔符
|
|
|
|
|
cornPrefix string // 任务key前缀
|
|
|
|
|
cornKeyIp string // 任务key
|
|
|
|
|
cornKeyChannel string // 任务频道key(任务key+ip)
|
|
|
|
|
cornKeyChannels string // 任务频道key通配符匹配(任务key+ip+_*)
|
|
|
|
|
debug bool // 调试
|
|
|
|
|
runVersion string // 运行版本
|
|
|
|
|
os string // 系统类型
|
|
|
|
|
arch string // 系统架构
|
|
|
|
|
maxProCs int // CPU核数
|
|
|
|
|
version string // GO版本
|
|
|
|
|
macAddrS string // Mac地址
|
|
|
|
|
insideIp string // 内网ip
|
|
|
|
|
outsideIp string // 外网ip
|
|
|
|
|
lockKeyPrefix string // 锁Key前缀 xxx_lock
|
|
|
|
|
lockKeySeparator string // 锁Key分隔符 :
|
|
|
|
|
cornKeyPrefix string // 任务Key前缀 xxx_cron
|
|
|
|
|
cornKeyCustom string // 任务Key自定义
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -50,14 +49,17 @@ type JobsGorm struct {
|
|
|
|
|
func NewJobsGorm(config *JobsGormConfig) (*JobsGorm, error) {
|
|
|
|
|
|
|
|
|
|
// 判断
|
|
|
|
|
if config.LockPrefix == "" {
|
|
|
|
|
if config.LockKeyPrefix == "" {
|
|
|
|
|
return nil, errors.New("需要配置锁Key前缀")
|
|
|
|
|
}
|
|
|
|
|
if config.LockSeparator == "" {
|
|
|
|
|
return nil, errors.New("需要配置锁分隔符")
|
|
|
|
|
if config.LockKeySeparator == "" {
|
|
|
|
|
return nil, errors.New("需要配置锁Key分隔符")
|
|
|
|
|
}
|
|
|
|
|
if config.CornPrefix == "" {
|
|
|
|
|
return nil, errors.New("需要配置任务前缀")
|
|
|
|
|
if config.CornKeyPrefix == "" {
|
|
|
|
|
return nil, errors.New("需要配置任务Key前缀")
|
|
|
|
|
}
|
|
|
|
|
if config.CornKeyCustom == "" {
|
|
|
|
|
return nil, errors.New("需要配置任务Key自定义")
|
|
|
|
|
}
|
|
|
|
|
if config.CurrentIp == "" {
|
|
|
|
|
return nil, errors.New("需要配置当前的IP")
|
|
|
|
@ -73,9 +75,10 @@ func NewJobsGorm(config *JobsGormConfig) (*JobsGorm, error) {
|
|
|
|
|
c.gormClient = config.GormClient
|
|
|
|
|
c.redisClient = config.RedisClient
|
|
|
|
|
c.config.outsideIp = config.CurrentIp
|
|
|
|
|
c.config.lockPrefix = config.LockPrefix
|
|
|
|
|
c.config.lockSeparator = config.LockSeparator
|
|
|
|
|
c.config.cornPrefix = config.CornPrefix
|
|
|
|
|
c.config.lockKeyPrefix = config.LockKeyPrefix
|
|
|
|
|
c.config.lockKeySeparator = config.LockKeySeparator
|
|
|
|
|
c.config.cornKeyPrefix = config.CornKeyPrefix
|
|
|
|
|
c.config.cornKeyCustom = config.CornKeyCustom
|
|
|
|
|
c.config.debug = config.Debug
|
|
|
|
|
|
|
|
|
|
// 锁
|
|
|
|
@ -101,20 +104,6 @@ func NewJobsGorm(config *JobsGormConfig) (*JobsGorm, error) {
|
|
|
|
|
return nil, errors.New(fmt.Sprintf("创建任务模型失败:%v\n", err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.config.cornKeyIp = c.getCornKeyIp()
|
|
|
|
|
c.config.cornKeyChannel = c.getCornKeyChannel()
|
|
|
|
|
c.config.cornKeyChannels = c.getCornKeyChannels()
|
|
|
|
|
|
|
|
|
|
if c.config.cornKeyIp == "" {
|
|
|
|
|
return nil, errors.New(fmt.Sprintf("没有配置 cornKeyIp:%s", c.config.cornKeyIp))
|
|
|
|
|
}
|
|
|
|
|
if c.config.cornKeyChannel == "" {
|
|
|
|
|
return nil, errors.New(fmt.Sprintf("没有配置 cornKeyChannel:%s", c.config.cornKeyChannel))
|
|
|
|
|
}
|
|
|
|
|
if c.config.cornKeyChannels == "" {
|
|
|
|
|
return nil, errors.New(fmt.Sprintf("没有配置 cornKeyChannels:%s", c.config.cornKeyChannels))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if c.config.debug == true {
|
|
|
|
|
log.Printf("JOBS配置:%+v\n", c.config)
|
|
|
|
|
}
|
|
|
|
|