cron

package
v0.0.0-...-118150e Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package cron 完成固定操作

Index

Constants

View Source
const (
	// Stop 停止状态
	Stop = iota
	// Pause 暂停状态
	Pause
	// Running 正在运行状态
	Running
)
View Source
const (
	TwoDay time.Duration = time.Hour * 24 * 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Channle

type Channle interface {
	[]dynamic.Info | []comment.Info | user.Info | daily.Info
}

Channle 任务执行后返回数据泛型

type Comment

type Comment struct {
	RID  int64
	Type comment.Type
	// contains filtered or unexported fields
}

Comment 评论区参数

func NewComment

func NewComment(rid, t int64, timeCell time.Duration, typ comment.Type, log *zap.Logger) *Comment

NewComment 初始化

func (Comment) Info

func (c Comment) Info() Info

Info 返回任务的信息

func (Comment) Next

func (c Comment) Next(t time.Time) time.Time

Next 下次运行时间

func (*Comment) Run

func (c *Comment) Run() interface{}

Run 获取最新评论内容

type Cron

type Cron[T Channle] struct {
	Ch chan T
	// contains filtered or unexported fields
}

Cron 管理所有任务,由 chan 传递数据 Enties([]Entity) <= Entity <= Tasker

func New

func New[T Channle]() Cron[T]

New 初始化

func (*Cron[T]) Add

func (c *Cron[T]) Add(id int64, task Tasker, startTime time.Time)

Add 添加新任务

func (Cron[T]) Info

func (c Cron[T]) Info() []Info

Info 返回所有任务的信息

func (Cron[T]) Start

func (c Cron[T]) Start()

Start 开始运行 调用 Stop 后请不要调用 Start,否则会触发 panic

func (Cron[T]) Stop

func (c Cron[T]) Stop()

Stop 停止监听 channle 中所有信息被读取之后返回

func (Cron[T]) StopByID

func (c Cron[T]) StopByID(id int64)

StopByID 停止指定 id 任务的执行

type Daily

type Daily struct {
	VideoAvID string
	// contains filtered or unexported fields
}

Daily 日常任务

func NewDaily

func NewDaily(api api.API, av string, log *zap.Logger) *Daily

NewDaily 初始化 默认时间间隔为 24 小时

func (Daily) Info

func (daily Daily) Info() Info

Info 返回任务的信息

func (Daily) Next

func (daily Daily) Next(t time.Time) time.Time

Next 下次运行时间

func (*Daily) Run

func (d *Daily) Run() interface{}

Run 运行日常任务

type Dynamic

type Dynamic struct {
	UID  int64
	Name string
	// contains filtered or unexported fields
}

Dynamic 动态信息

func NewDynamic

func NewDynamic(uid, ti int64, timeCell time.Duration, log *zap.Logger) *Dynamic

NewDynamic 初始化

func (Dynamic) Info

func (d Dynamic) Info() Info

Info 返回任务的信息

func (Dynamic) Next

func (d Dynamic) Next(t time.Time) time.Time

Next 下次运行时间

func (*Dynamic) Run

func (d *Dynamic) Run() interface{}

Run 监听最新动态

type Entities

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

Entities 保存所有 Entity 用于排序

func (Entities) Len

func (e Entities) Len() int

func (Entities) Less

func (e Entities) Less(i, j int) bool

func (*Entities) Pop

func (e *Entities) Pop() interface{}

func (*Entities) Push

func (e *Entities) Push(v interface{})

func (*Entities) Remove

func (e *Entities) Remove()

Remove 从队列中删除

func (*Entities) Reset

func (e *Entities) Reset() time.Time

Reset 重新排列队列

func (Entities) Swap

func (e Entities) Swap(i, j int)

type Entity

type Entity struct {
	ID   int64
	Task Tasker

	// Prev 待执行时间
	Prev time.Time
	// contains filtered or unexported fields
}

Entity 保存下一次和这次的运行时间

func (*Entity) Done

func (entity *Entity) Done()

Done 调整执行时间

type Info

type Info struct {
	// ID uid 或 rid
	ID int64
	// Type 动态类型
	Type comment.Type
	// TimeCell 时间间隔
	TimeCell time.Duration
	// Time 动态时间
	Time int64
	// Name 昵称
	Name string
}

Info 任务的信息

type Tasker

type Tasker interface {
	// Run(chan<- interface{}, *sync.WaitGroup)
	Run() interface{}
	Next(time.Time) time.Time
	Info() Info
}

Tasker 任务接口

type User

type User struct {
	UID  int64
	Name string
	Face string
	Sign string
	// contains filtered or unexported fields
}

User 用户信息

func NewUser

func NewUser(uid int64, timeCell time.Duration, log *zap.Logger) *User

NewUser 初始化

func (User) Info

func (user User) Info() Info

Info 监听用户的部分信息

func (User) Next

func (user User) Next(t time.Time) time.Time

Next 下次运行时间

func (*User) Run

func (u *User) Run() interface{}

Run 监听用户信息变更

Jump to

Keyboard shortcuts

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