gojobs

package
v1.0.215 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeAbnormal = 0                              // 异常
	CodeError    = http.StatusInternalServerError // 失败
	CodeSuccess  = http.StatusOK                  // 成功
	CodeEnd      = http.StatusCreated             // 结束
)
View Source
const (
	TASK_IN      = "IN"      // 任务运行
	TASK_SUCCESS = "SUCCESS" // 任务完成
	TASK_ERROR   = "ERROR"   // 任务异常
	TASK_TIMEOUT = "TIMEOUT" // 任务超时
	TASK_WAIT    = "WAIT"    // 任务等待
)
View Source
const (
	SpecifyIpNull = "0.0.0.0"
)

Variables

View Source
var (
	TaskIsExist = errors.New("任务已存在")
)

Functions

func GetHour

func GetHour(n int64) *hour

GetHour 每天n点执行一次

func GetHourInterval

func GetHourInterval(n int64) *hourInterval

GetHourInterval 每隔n小时执行一次

func GetMinutes

func GetMinutes(n int64) *minutes

GetMinutes 每隔n分钟执行一次

func GetSeconds

func GetSeconds(n int64) *seconds

GetSeconds 每隔n秒执行一次

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client 实例

func NewClient

func NewClient(config *ClientConfig) (*Client, error)

NewClient 创建实例

func (*Client) ConfigRunSLogClientFun added in v1.0.199

func (c *Client) ConfigRunSLogClientFun(sLogFun golog.SLogFun)

ConfigRunSLogClientFun 运行日志配置

func (*Client) ConfigSLogClientFun added in v1.0.164

func (c *Client) ConfigSLogClientFun(sLogFun golog.SLogFun)

ConfigSLogClientFun 日志配置

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) EditTask added in v1.0.52

func (c *Client) EditTask(tx *gorm.DB, id uint) *gorm.DB

EditTask 任务修改

func (*Client) Filter added in v1.0.97

func (c *Client) Filter(ctx context.Context, isMandatoryIp bool, specifyIp string, tasks []jobs_gorm_model.Task, isPrint bool) (newTasks []jobs_gorm_model.Task)

Filter 过滤 ctx 上下文 isMandatoryIp 强制当前ip specifyIp 指定Ip tasks 过滤前的数据 newTasks 过滤后的数据

func (*Client) GetCurrentIp added in v1.0.52

func (c *Client) GetCurrentIp() string

GetCurrentIp 获取当前ip

func (*Client) GetDb added in v1.0.52

func (c *Client) GetDb() *gorm.DB

GetDb 获取数据库驱动

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

func (c *Client) GetSubscribeAddress() string

GetSubscribeAddress 获取订阅地址

func (*Client) GetSubscribeClientList added in v1.0.52

func (c *Client) GetSubscribeClientList(ctx context.Context) (client []string, err error)

GetSubscribeClientList 获取在线的客户端

func (*Client) Lock added in v1.0.52

func (c *Client) Lock(ctx context.Context, info jobs_gorm_model.Task, id any) (string, error)

Lock 上锁

func (*Client) LockCustomId added in v1.0.52

func (c *Client) LockCustomId(ctx context.Context, info jobs_gorm_model.Task) (string, error)

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

func (c *Client) LockForeverId(ctx context.Context, info jobs_gorm_model.Task) (string, error)

LockForeverId 永远上锁

func (*Client) LockId added in v1.0.52

func (c *Client) LockId(ctx context.Context, info jobs_gorm_model.Task) (string, error)

LockId 上锁

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) Println added in v1.0.99

func (c *Client) Println(isPrint bool, v ...any)

func (*Client) Publish added in v1.0.52

func (c *Client) Publish(ctx context.Context, channel string, message interface{}) error

Publish 发布 ctx 上下文 channel 频道 message 消息

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) StartTask added in v1.0.52

func (c *Client) StartTask(ctx context.Context, tx *gorm.DB, id uint) error

StartTask 任务启动

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) TaskFindAllErrorType added in v1.0.100

func (c *Client) TaskFindAllErrorType(ctx context.Context, tx *gorm.DB, Type string) []jobs_gorm_model.Task

TaskFindAllErrorType 查询多任务 - 任务异常

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) TaskFindAllInType added in v1.0.100

func (c *Client) TaskFindAllInType(ctx context.Context, tx *gorm.DB, Type string) []jobs_gorm_model.Task

TaskFindAllInType 查询多任务 - 任务运行

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) TaskFindAllSuccessType added in v1.0.100

func (c *Client) TaskFindAllSuccessType(ctx context.Context, tx *gorm.DB, Type string) []jobs_gorm_model.Task

TaskFindAllSuccessType 查询多任务 - 任务完成

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) TaskFindAllTimeoutType added in v1.0.100

func (c *Client) TaskFindAllTimeoutType(ctx context.Context, tx *gorm.DB, Type string) []jobs_gorm_model.Task

TaskFindAllTimeoutType 查询多任务 - 任务超时

func (*Client) TaskFindAllType added in v1.0.100

func (c *Client) TaskFindAllType(ctx context.Context, tx *gorm.DB, Type string, frequency int64) (results []jobs_gorm_model.Task)

TaskFindAllType 查询多任务

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) TaskFindAllWaitType added in v1.0.100

func (c *Client) TaskFindAllWaitType(ctx context.Context, tx *gorm.DB, Type string) []jobs_gorm_model.Task

TaskFindAllWaitType 查询多任务 - 任务等待

func (*Client) TaskLogRecord added in v1.0.52

func (c *Client) TaskLogRecord(ctx context.Context, task jobs_gorm_model.Task, runId string, 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

func (c *Client) TaskTakeIn(ctx context.Context, tx *gorm.DB, customId string) jobs_gorm_model.Task

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) Unlock added in v1.0.52

func (c *Client) Unlock(ctx context.Context, info jobs_gorm_model.Task, id any) error

Unlock Lock 解锁

func (*Client) UnlockCustomId added in v1.0.52

func (c *Client) UnlockCustomId(ctx context.Context, info jobs_gorm_model.Task) error

UnlockCustomId 解锁

func (*Client) UnlockId added in v1.0.52

func (c *Client) UnlockId(ctx context.Context, info jobs_gorm_model.Task) error

UnlockId 解锁

func (*Client) UpdateFrequency added in v1.0.52

func (c *Client) UpdateFrequency(ctx context.Context, tx *gorm.DB, id uint, frequency int64) error

UpdateFrequency 更新任务频率

type ClientConfig

type ClientConfig struct {
	GormClientFun  dorm.GormClientFun  // 数据库驱动
	RedisClientFun dorm.RedisClientFun // 数据库驱动
	RedisPrefixFun redisPrefixFun      // 前缀
	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 NewCron

func NewCron() *Cron

NewCron 创建一个定时任务管理器

func (*Cron) AddJobByFunc

func (c *Cron) AddJobByFunc(id string, spec string, f func()) error

AddJobByFunc 添加函数作为定时任务 id:唯一任务id spec:配置定时执行时间表达式 f:需要执行的任务方法

func (*Cron) AddJobByInterface

func (c *Cron) AddJobByInterface(id string, spec string, cmd cron.Job) error

AddJobByInterface 实现接口的方式添加定时任务 id:唯一任务id spec:配置定时执行时间表达式 cmd:需要执行的任务方法

func (*Cron) DelByID

func (c *Cron) DelByID(id string)

DelByID 删除任务 id:唯一任务id

func (*Cron) Ids

func (c *Cron) Ids() []string

Ids ...

func (*Cron) IsExistsJob

func (c *Cron) IsExistsJob(id string) bool

IsExistsJob 判断是否存在任务 id:唯一任务id

func (*Cron) Start

func (c *Cron) Start()

Start 启动任务

func (*Cron) Stop

func (c *Cron) Stop()

Stop 关闭任务

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 解锁

func (*TaskLockOperation) UnlockId added in v1.0.52

func (tlo *TaskLockOperation) UnlockId(ctx context.Context) error

UnlockId 解锁

type TaskLog added in v1.0.52

type TaskLog struct {
	TaskId           uint   `json:"task_id"`            // 任务编号
	TaskRunId        string `json:"task_run_id"`        // 执行编号
	TaskResultStatus string `json:"task_result_status"` // 执行状态
	TaskResultCode   int    `json:"task_result_code"`   // 执行状态码
	TaskResultDesc   string `json:"task_result_desc"`   // 执行结果
	SystemHostName   string `json:"system_host_name"`   // 主机名
	SystemInsideIp   string `json:"system_inside_ip"`   // 内网ip
	SystemOs         string `json:"system_os"`          // 系统类型
	SystemArch       string `json:"system_arch"`        // 系统架构
	GoVersion        string `json:"go_version"`         // go版本
	SdkVersion       string `json:"sdk_version"`        // sdk版本
	SystemOutsideIp  string `json:"system_outside_ip"`  // 外网ip
}

TaskLog 任务日志模型

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL