Documentation ¶
Index ¶
- Constants
- Variables
- func GetHour(n int64) *hour
- func GetHourInterval(n int64) *hourInterval
- func GetMinutes(n int64) *minutes
- func GetSeconds(n int64) *seconds
- type Client
- func (c *Client) CreateInCustomId(ctx context.Context, config *ConfigCreateInCustomId) error
- func (c *Client) CreateInCustomIdMaxNumber(ctx context.Context, config *ConfigCreateInCustomIdMaxNumber) error
- func (c *Client) CreateInCustomIdMaxNumberOnly(ctx context.Context, config *ConfigCreateInCustomIdMaxNumberOnly) error
- func (c *Client) CreateInCustomIdOnly(ctx context.Context, config *ConfigCreateInCustomIdOnly) error
- func (c *Client) CreateWaitCustomId(ctx context.Context, config *ConfigCreateWaitCustomId) error
- func (c *Client) EditTask(tx *gorm.DB, id uint) *gorm.DB
- func (c *Client) GetCurrentIp() string
- func (c *Client) GetDb() *gorm.DB
- func (c *Client) GetIssueAddress(ctx context.Context, workers []string, v *jobs_gorm_model.Task) (string, error)
- func (c *Client) GetRedis() *redis.Client
- func (c *Client) GetSubscribeAddress() string
- func (c *Client) GetSubscribeClientList(ctx context.Context) (client []string, err error)
- func (c *Client) GormTaskLogDelete(ctx context.Context, hour int64) error
- func (c *Client) GormTaskLogRecord(ctx context.Context, task jobs_gorm_model.Task, runId string, ...)
- func (c *Client) Lock(ctx context.Context, info jobs_gorm_model.Task, id any) (string, error)
- func (c *Client) LockCustomId(ctx context.Context, info jobs_gorm_model.Task) (string, error)
- func (c *Client) LockForever(ctx context.Context, info jobs_gorm_model.Task, id any) (string, error)
- func (c *Client) LockForeverCustomId(ctx context.Context, info jobs_gorm_model.Task) (string, error)
- func (c *Client) LockForeverId(ctx context.Context, info jobs_gorm_model.Task) (string, error)
- func (c *Client) LockId(ctx context.Context, info jobs_gorm_model.Task) (string, error)
- func (c *Client) NewLock(task jobs_gorm_model.Task) (*TaskLockOperation, error)
- func (c *Client) PSubscribe(ctx context.Context) SubscribeResult
- func (c *Client) Publish(ctx context.Context, channel string, message interface{}) error
- func (c *Client) Run(ctx context.Context, task jobs_gorm_model.Task, taskResultCode int, ...)
- func (c *Client) StartTask(ctx context.Context, tx *gorm.DB, id uint) error
- func (c *Client) StartTaskCustom(ctx context.Context, tx *gorm.DB, customId string, customSequence int64) error
- func (c *Client) Subscribe(ctx context.Context) SubscribeResult
- func (c *Client) TaskFindAll(ctx context.Context, tx *gorm.DB, frequency int64) (results []jobs_gorm_model.Task)
- func (c *Client) TaskFindAllError(ctx context.Context, tx *gorm.DB, frequency int64) []jobs_gorm_model.Task
- func (c *Client) TaskFindAllIn(ctx context.Context, tx *gorm.DB, frequency int64) []jobs_gorm_model.Task
- func (c *Client) TaskFindAllSuccess(ctx context.Context, tx *gorm.DB, frequency int64) []jobs_gorm_model.Task
- func (c *Client) TaskFindAllTimeout(ctx context.Context, tx *gorm.DB, frequency int64) []jobs_gorm_model.Task
- func (c *Client) TaskFindAllWait(ctx context.Context, tx *gorm.DB, frequency int64) []jobs_gorm_model.Task
- func (c *Client) TaskLogRecord(ctx context.Context, task jobs_gorm_model.Task, taskResultCode int, ...)
- func (c *Client) TaskTake(ctx context.Context, tx *gorm.DB, customId string) (result jobs_gorm_model.Task)
- func (c *Client) TaskTakeError(ctx context.Context, tx *gorm.DB, customId string) jobs_gorm_model.Task
- func (c *Client) TaskTakeId(ctx context.Context, tx *gorm.DB, id uint) (result jobs_gorm_model.Task)
- func (c *Client) TaskTakeIn(ctx context.Context, tx *gorm.DB, customId string) jobs_gorm_model.Task
- func (c *Client) TaskTakeSuccess(ctx context.Context, tx *gorm.DB, customId string) jobs_gorm_model.Task
- func (c *Client) TaskTakeTimeout(ctx context.Context, tx *gorm.DB, customId string) jobs_gorm_model.Task
- func (c *Client) TaskTakeWait(ctx context.Context, tx *gorm.DB, customId string) jobs_gorm_model.Task
- func (c *Client) TaskTypeTake(ctx context.Context, tx *gorm.DB, customId, Type string) (result jobs_gorm_model.Task)
- func (c *Client) TaskTypeTakeError(ctx context.Context, tx *gorm.DB, customId, Type string) jobs_gorm_model.Task
- func (c *Client) TaskTypeTakeIn(ctx context.Context, tx *gorm.DB, customId, Type string) jobs_gorm_model.Task
- func (c *Client) TaskTypeTakeSuccess(ctx context.Context, tx *gorm.DB, customId, Type string) jobs_gorm_model.Task
- func (c *Client) TaskTypeTakeTimeout(ctx context.Context, tx *gorm.DB, customId, Type string) jobs_gorm_model.Task
- func (c *Client) TaskTypeTakeWait(ctx context.Context, tx *gorm.DB, customId, Type string) jobs_gorm_model.Task
- func (c *Client) Unlock(ctx context.Context, info jobs_gorm_model.Task, id any) error
- func (c *Client) UnlockCustomId(ctx context.Context, info jobs_gorm_model.Task) error
- func (c *Client) UnlockId(ctx context.Context, info jobs_gorm_model.Task) error
- func (c *Client) UpdateFrequency(ctx context.Context, tx *gorm.DB, id uint, frequency int64) error
- type ClientConfig
- type ConfigCreateInCustomId
- type ConfigCreateInCustomIdMaxNumber
- type ConfigCreateInCustomIdMaxNumberOnly
- type ConfigCreateInCustomIdOnly
- type ConfigCreateWaitCustomId
- type Cron
- type SubscribeResult
- type TaskLockOperation
- func (tlo *TaskLockOperation) Lock(ctx context.Context, id any) error
- func (tlo *TaskLockOperation) LockCustomId(ctx context.Context) error
- func (tlo *TaskLockOperation) LockForever(ctx context.Context, id any) error
- func (tlo *TaskLockOperation) LockForeverCustomId(ctx context.Context) error
- func (tlo *TaskLockOperation) LockForeverId(ctx context.Context) error
- func (tlo *TaskLockOperation) LockId(ctx context.Context) error
- func (tlo *TaskLockOperation) Unlock(ctx context.Context, id any) error
- func (tlo *TaskLockOperation) UnlockCustomId(ctx context.Context) error
- func (tlo *TaskLockOperation) UnlockId(ctx context.Context) error
Constants ¶
const ( CodeAbnormal = 0 // 异常 CodeError = http.StatusInternalServerError // 失败 CodeSuccess = http.StatusOK // 成功 CodeEnd = http.StatusCreated // 结束 )
const ( TASK_IN = "IN" // 任务运行 TASK_SUCCESS = "SUCCESS" // 任务完成 TASK_ERROR = "ERROR" // 任务异常 TASK_TIMEOUT = "TIMEOUT" // 任务超时 TASK_WAIT = "WAIT" // 任务等待 )
const (
SpecifyIpNull = "0.0.0.0"
)
Variables ¶
var (
TaskIsExist = errors.New("任务已存在")
)
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 实例
func (*Client) CreateInCustomId ¶ added in v1.0.52
func (c *Client) CreateInCustomId(ctx context.Context, config *ConfigCreateInCustomId) error
CreateInCustomId 创建正在运行任务
func (*Client) CreateInCustomIdMaxNumber ¶ added in v1.0.52
func (c *Client) CreateInCustomIdMaxNumber(ctx context.Context, config *ConfigCreateInCustomIdMaxNumber) error
CreateInCustomIdMaxNumber 创建正在运行任务并限制数量
func (*Client) CreateInCustomIdMaxNumberOnly ¶ added in v1.0.52
func (c *Client) CreateInCustomIdMaxNumberOnly(ctx context.Context, config *ConfigCreateInCustomIdMaxNumberOnly) error
CreateInCustomIdMaxNumberOnly 创建正在运行唯一任务并限制数量
func (*Client) CreateInCustomIdOnly ¶ added in v1.0.52
func (c *Client) CreateInCustomIdOnly(ctx context.Context, config *ConfigCreateInCustomIdOnly) error
CreateInCustomIdOnly 创建正在运行唯一任务
func (*Client) CreateWaitCustomId ¶ added in v1.0.52
func (c *Client) CreateWaitCustomId(ctx context.Context, config *ConfigCreateWaitCustomId) error
CreateWaitCustomId 创建正在运行任务
func (*Client) GetCurrentIp ¶ added in v1.0.52
GetCurrentIp 获取当前ip
func (*Client) GetIssueAddress ¶ added in v1.0.52
func (c *Client) GetIssueAddress(ctx context.Context, workers []string, v *jobs_gorm_model.Task) (string, error)
GetIssueAddress 获取下发地址 workers 在线列表 v 任务信息 --- address 下发地址 err 错误信息
func (*Client) GetRedis ¶ added in v1.0.52
func (c *Client) GetRedis() *redis.Client
GetRedis 获取缓存数据库驱动
func (*Client) GetSubscribeAddress ¶ added in v1.0.52
GetSubscribeAddress 获取订阅地址
func (*Client) GetSubscribeClientList ¶ added in v1.0.52
GetSubscribeClientList 获取在线的客户端
func (*Client) GormTaskLogDelete ¶ added in v1.0.52
GormTaskLogDelete 删除
func (*Client) GormTaskLogRecord ¶ added in v1.0.52
func (c *Client) GormTaskLogRecord(ctx context.Context, task jobs_gorm_model.Task, runId string, taskResultCode int, taskResultDesc string)
GormTaskLogRecord 记录
func (*Client) LockCustomId ¶ added in v1.0.52
LockCustomId 上锁
func (*Client) LockForever ¶ added in v1.0.52
func (c *Client) LockForever(ctx context.Context, info jobs_gorm_model.Task, id any) (string, error)
LockForever 永远上锁
func (*Client) LockForeverCustomId ¶ added in v1.0.52
func (c *Client) LockForeverCustomId(ctx context.Context, info jobs_gorm_model.Task) (string, error)
LockForeverCustomId 永远上锁
func (*Client) LockForeverId ¶ added in v1.0.52
LockForeverId 永远上锁
func (*Client) NewLock ¶ added in v1.0.52
func (c *Client) NewLock(task jobs_gorm_model.Task) (*TaskLockOperation, error)
func (*Client) PSubscribe ¶ added in v1.0.52
func (c *Client) PSubscribe(ctx context.Context) SubscribeResult
PSubscribe 订阅,支持通配符匹配(ch_user_*)
func (*Client) Run ¶ added in v1.0.52
func (c *Client) Run(ctx context.Context, task jobs_gorm_model.Task, taskResultCode int, taskResultDesc string)
Run 运行
func (*Client) StartTaskCustom ¶ added in v1.0.52
func (c *Client) StartTaskCustom(ctx context.Context, tx *gorm.DB, customId string, customSequence int64) error
StartTaskCustom 任务启动自定义
func (*Client) Subscribe ¶ added in v1.0.52
func (c *Client) Subscribe(ctx context.Context) SubscribeResult
Subscribe 订阅
func (*Client) TaskFindAll ¶ added in v1.0.52
func (c *Client) TaskFindAll(ctx context.Context, tx *gorm.DB, frequency int64) (results []jobs_gorm_model.Task)
TaskFindAll 查询多任务
func (*Client) TaskFindAllError ¶ added in v1.0.52
func (c *Client) TaskFindAllError(ctx context.Context, tx *gorm.DB, frequency int64) []jobs_gorm_model.Task
TaskFindAllError 查询多任务 - 任务异常
func (*Client) TaskFindAllIn ¶ added in v1.0.52
func (c *Client) TaskFindAllIn(ctx context.Context, tx *gorm.DB, frequency int64) []jobs_gorm_model.Task
TaskFindAllIn 查询多任务 - 任务运行
func (*Client) TaskFindAllSuccess ¶ added in v1.0.52
func (c *Client) TaskFindAllSuccess(ctx context.Context, tx *gorm.DB, frequency int64) []jobs_gorm_model.Task
TaskFindAllSuccess 查询多任务 - 任务完成
func (*Client) TaskFindAllTimeout ¶ added in v1.0.52
func (c *Client) TaskFindAllTimeout(ctx context.Context, tx *gorm.DB, frequency int64) []jobs_gorm_model.Task
TaskFindAllTimeout 查询多任务 - 任务超时
func (*Client) TaskFindAllWait ¶ added in v1.0.52
func (c *Client) TaskFindAllWait(ctx context.Context, tx *gorm.DB, frequency int64) []jobs_gorm_model.Task
TaskFindAllWait 查询多任务 - 任务等待
func (*Client) TaskLogRecord ¶ added in v1.0.52
func (c *Client) TaskLogRecord(ctx context.Context, task jobs_gorm_model.Task, taskResultCode int, taskResultDesc string)
TaskLogRecord 记录
func (*Client) TaskTake ¶ added in v1.0.52
func (c *Client) TaskTake(ctx context.Context, tx *gorm.DB, customId string) (result jobs_gorm_model.Task)
TaskTake 自定义编号查询任务
func (*Client) TaskTakeError ¶ added in v1.0.52
func (c *Client) TaskTakeError(ctx context.Context, tx *gorm.DB, customId string) jobs_gorm_model.Task
TaskTakeError 查询单任务 - 任务异常
func (*Client) TaskTakeId ¶ added in v1.0.52
func (c *Client) TaskTakeId(ctx context.Context, tx *gorm.DB, id uint) (result jobs_gorm_model.Task)
TaskTakeId 编号查询任务
func (*Client) TaskTakeIn ¶ added in v1.0.52
TaskTakeIn 查询单任务 - 任务运行
func (*Client) TaskTakeSuccess ¶ added in v1.0.52
func (c *Client) TaskTakeSuccess(ctx context.Context, tx *gorm.DB, customId string) jobs_gorm_model.Task
TaskTakeSuccess 查询单任务 - 任务完成
func (*Client) TaskTakeTimeout ¶ added in v1.0.52
func (c *Client) TaskTakeTimeout(ctx context.Context, tx *gorm.DB, customId string) jobs_gorm_model.Task
TaskTakeTimeout 查询单任务 - 任务超时
func (*Client) TaskTakeWait ¶ added in v1.0.52
func (c *Client) TaskTakeWait(ctx context.Context, tx *gorm.DB, customId string) jobs_gorm_model.Task
TaskTakeWait 查询单任务 - 任务等待
func (*Client) TaskTypeTake ¶ added in v1.0.52
func (c *Client) TaskTypeTake(ctx context.Context, tx *gorm.DB, customId, Type string) (result jobs_gorm_model.Task)
TaskTypeTake 查询单任务
func (*Client) TaskTypeTakeError ¶ added in v1.0.52
func (c *Client) TaskTypeTakeError(ctx context.Context, tx *gorm.DB, customId, Type string) jobs_gorm_model.Task
TaskTypeTakeError 查询单任务 - 任务异常
func (*Client) TaskTypeTakeIn ¶ added in v1.0.52
func (c *Client) TaskTypeTakeIn(ctx context.Context, tx *gorm.DB, customId, Type string) jobs_gorm_model.Task
TaskTypeTakeIn 查询单任务 - 任务运行
func (*Client) TaskTypeTakeSuccess ¶ added in v1.0.52
func (c *Client) TaskTypeTakeSuccess(ctx context.Context, tx *gorm.DB, customId, Type string) jobs_gorm_model.Task
TaskTypeTakeSuccess 查询单任务 - 任务完成
func (*Client) TaskTypeTakeTimeout ¶ added in v1.0.52
func (c *Client) TaskTypeTakeTimeout(ctx context.Context, tx *gorm.DB, customId, Type string) jobs_gorm_model.Task
TaskTypeTakeTimeout 查询单任务 - 任务超时
func (*Client) TaskTypeTakeWait ¶ added in v1.0.52
func (c *Client) TaskTypeTakeWait(ctx context.Context, tx *gorm.DB, customId, Type string) jobs_gorm_model.Task
TaskTypeTakeWait 查询单任务 - 任务等待
func (*Client) UnlockCustomId ¶ added in v1.0.52
UnlockCustomId 解锁
type ClientConfig ¶
type ClientConfig struct { GormClientFun dorm.GormClientFun // 数据库驱动 RedisClientFun dorm.RedisClientFun // 数据库驱动 RedisPrefixFun redisPrefixFun // 前缀 ZapLog *golog.ZapLog // 日志服务 CurrentIp string // 当前ip }
ClientConfig 实例配置
type ConfigCreateInCustomId ¶
type ConfigCreateInCustomId struct { Tx *gorm.DB // 驱动 Params string // 参数 Frequency int64 // 频率(秒单位) CustomId string // 自定义编号 CustomSequence int64 // 自定义顺序 Type string // 类型 TypeName string // 类型名称 SpecifyIp string // 指定外网IP CurrentIp string // 当前外网IP }
ConfigCreateInCustomId 创建正在运行任务
type ConfigCreateInCustomIdMaxNumber ¶
type ConfigCreateInCustomIdMaxNumber struct { Tx *gorm.DB // 驱动 Params string // 参数 Frequency int64 // 频率(秒单位) MaxNumber int64 // 最大次数 CustomId string // 自定义编号 CustomSequence int64 // 自定义顺序 Type string // 类型 TypeName string // 类型名称 SpecifyIp string // 指定外网IP CurrentIp string // 当前外网IP }
ConfigCreateInCustomIdMaxNumber 创建正在运行任务并限制数量
type ConfigCreateInCustomIdMaxNumberOnly ¶
type ConfigCreateInCustomIdMaxNumberOnly struct { Tx *gorm.DB // 驱动 Params string // 参数 Frequency int64 // 频率(秒单位) MaxNumber int64 // 最大次数 CustomId string // 自定义编号 CustomSequence int64 // 自定义顺序 Type string // 类型 TypeName string // 类型名称 SpecifyIp string // 指定外网IP CurrentIp string // 当前外网IP }
ConfigCreateInCustomIdMaxNumberOnly 创建正在运行唯一任务并限制数量
type ConfigCreateInCustomIdOnly ¶
type ConfigCreateInCustomIdOnly struct { Tx *gorm.DB // 驱动 Params string // 参数 Frequency int64 // 频率(秒单位) CustomId string // 自定义编号 CustomSequence int64 // 自定义顺序 Type string // 类型 TypeName string // 类型名称 SpecifyIp string // 指定外网IP CurrentIp string // 当前外网IP }
ConfigCreateInCustomIdOnly 创建正在运行唯一任务
type ConfigCreateWaitCustomId ¶ added in v1.0.52
type ConfigCreateWaitCustomId struct { Tx *gorm.DB // 驱动 Params string // 参数 Frequency int64 // 频率(秒单位) CustomId string // 自定义编号 CustomSequence int64 // 自定义顺序 Type string // 类型 TypeName string // 类型名称 SpecifyIp string // 指定外网IP CurrentIp string // 当前外网IP }
ConfigCreateWaitCustomId 创建正在运行任务
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
Cron 定时任务管理器
func (*Cron) AddJobByFunc ¶
AddJobByFunc 添加函数作为定时任务 id:唯一任务id spec:配置定时执行时间表达式 f:需要执行的任务方法
func (*Cron) AddJobByInterface ¶
AddJobByInterface 实现接口的方式添加定时任务 id:唯一任务id spec:配置定时执行时间表达式 cmd:需要执行的任务方法
func (*Cron) IsExistsJob ¶
IsExistsJob 判断是否存在任务 id:唯一任务id
type SubscribeResult ¶ added in v1.0.51
type SubscribeResult struct { Message *redis.PubSub // contains filtered or unexported fields }
type TaskLockOperation ¶ added in v1.0.52
type TaskLockOperation struct {
// contains filtered or unexported fields
}
func (*TaskLockOperation) Lock ¶ added in v1.0.52
func (tlo *TaskLockOperation) Lock(ctx context.Context, id any) error
Lock 上锁
func (*TaskLockOperation) LockCustomId ¶ added in v1.0.52
func (tlo *TaskLockOperation) LockCustomId(ctx context.Context) error
LockCustomId 上锁
func (*TaskLockOperation) LockForever ¶ added in v1.0.52
func (tlo *TaskLockOperation) LockForever(ctx context.Context, id any) error
LockForever 永远上锁
func (*TaskLockOperation) LockForeverCustomId ¶ added in v1.0.52
func (tlo *TaskLockOperation) LockForeverCustomId(ctx context.Context) error
LockForeverCustomId 永远上锁
func (*TaskLockOperation) LockForeverId ¶ added in v1.0.52
func (tlo *TaskLockOperation) LockForeverId(ctx context.Context) error
LockForeverId 永远上锁
func (*TaskLockOperation) LockId ¶ added in v1.0.52
func (tlo *TaskLockOperation) LockId(ctx context.Context) error
LockId 上锁
func (*TaskLockOperation) Unlock ¶ added in v1.0.52
func (tlo *TaskLockOperation) Unlock(ctx context.Context, id any) error
Unlock 解锁
func (*TaskLockOperation) UnlockCustomId ¶ added in v1.0.52
func (tlo *TaskLockOperation) UnlockCustomId(ctx context.Context) error
UnlockCustomId 解锁