gojobs

package
v1.0.58 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: MIT Imports: 27 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) 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) 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) GetMongoDb added in v1.0.52

func (c *Client) GetMongoDb() *mongo.Client

GetMongoDb 获取数据库驱动

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

func (c *Client) GormTaskLogDelete(ctx context.Context, hour int64) error

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

func (c *Client) MongoTaskLogDelete(ctx context.Context, hour int64) (*mongo.DeleteResult, error)

MongoTaskLogDelete 删除

func (*Client) MongoTaskLogRecord added in v1.0.52

func (c *Client) MongoTaskLogRecord(ctx context.Context, task jobs_gorm_model.Task, runId string, taskResultCode int, taskResultDesc string)

MongoTaskLogRecord 记录

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) 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) 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

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  // 数据库驱动
	MongoClientFun dorm.MongoClientFun // 数据库驱动
	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 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 {
	LogId   primitive.ObjectID `json:"log_id,omitempty" bson:"_id,omitempty"` //【记录】编号
	LogTime primitive.DateTime `json:"log_time,omitempty" bson:"log_time"`    //【记录】时间
	Task    struct {
		Id         uint   `json:"id" bson:"id"`                   //【任务】编号
		RunId      string `json:"run_id" bson:"run_id"`           //【任务】执行编号
		ResultCode int    `json:"result_code" bson:"result_code"` //【任务】执行状态码
		ResultDesc string `json:"result_desc" bson:"result_desc"` //【任务】执行结果
		ResultTime string `json:"result_time" bson:"result_time"` //【任务】执行时间
	} `json:"task,omitempty" bson:"task,omitempty"` //【任务】信息
	System struct {
		Hostname        string  `json:"hostname" bson:"hostname"`                                       //【系统】主机名
		Os              string  `json:"os" bson:"os"`                                                   //【系统】系统类型
		Version         string  `json:"version" bson:"version"`                                         //【系统】系统版本
		Kernel          string  `json:"kernel" bson:"kernel"`                                           //【系统】系统内核
		KernelVersion   string  `json:"kernel_version" bson:"kernel_version"`                           //【系统】系统内核版本
		BootTime        string  `json:"boot_time" bson:"boot_time"`                                     //【系统】系统开机时间
		CpuCores        int     `json:"cpu_cores,omitempty" bson:"cpu_cores,omitempty"`                 //【系统】CPU核数
		CpuModelName    string  `json:"cpu_model_name,omitempty" bson:"cpu_model_name,omitempty"`       //【系统】CPU型号名称
		CpuMhz          float64 `json:"cpu_mhz,omitempty" bson:"cpu_mhz,omitempty"`                     //【系统】CPU兆赫
		InsideIp        string  `json:"inside_ip" bson:"inside_ip"`                                     //【系统】内网ip
		OutsideIp       string  `json:"outside_ip" bson:"outside_ip"`                                   //【系统】外网ip
		GoVersion       string  `json:"go_version,omitempty" bson:"go_version,omitempty"`               //【系统】go版本
		SdkVersion      string  `json:"sdk_version,omitempty" bson:"sdk_version,omitempty"`             //【系统】sdk版本
		MongoVersion    string  `json:"mongo_version,omitempty" bson:"mongo_version,omitempty"`         //【系统】mongo版本
		MongoSdkVersion string  `json:"mongo_sdk_version,omitempty" bson:"mongo_sdk_version,omitempty"` //【系统】mongo sdk版本
		RedisVersion    string  `json:"redis_version,omitempty" bson:"redis_version,omitempty"`         //【系统】redis版本
		RedisSdkVersion string  `json:"redis_sdk_version,omitempty" bson:"redis_sdk_version,omitempty"` //【系统】redis sdk版本
		LogVersion      string  `json:"log_version,omitempty" bson:"log_version,omitempty"`             //【系统】log版本
	} `json:"system,omitempty" bson:"system,omitempty"` //【系统】信息
}

TaskLog 任务日志模型

func (TaskLog) CollectionName added in v1.0.52

func (TaskLog) CollectionName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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