test
Signed-off-by: dongl <2725096176@qq.com>
This commit is contained in:
parent
5697433466
commit
6a6842be4e
@ -7,39 +7,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func SignInBegin(msg *openwechat.Message) {
|
func SignInBegin(msg *openwechat.Message) {
|
||||||
// 新建一个定时任务对象
|
|
||||||
// 根据cron表达式进行时间调度,cron可以精确到秒,大部分表达式格式也是从秒开始。
|
|
||||||
//crontab := cron.New() 默认从分开始进行时间调度
|
|
||||||
crontab := cron.New(cron.WithSeconds()) //精确到秒
|
|
||||||
|
|
||||||
//定义定时器调用的任务函数
|
|
||||||
task := func() {
|
|
||||||
// 获取全部群聊
|
|
||||||
groups, err := self.Groups()
|
|
||||||
fmt.Println(groups, err)
|
|
||||||
|
|
||||||
// 发送到微信
|
|
||||||
self.SendTextToGroup("叫啥好呢", "同志们开卷!")
|
|
||||||
}
|
|
||||||
//定时任务
|
|
||||||
spec := "*/10 * * * * ?" //cron表达式,每五秒一次
|
|
||||||
// 添加定时任务,
|
|
||||||
crontab.AddFunc(spec, task)
|
|
||||||
// 启动定时器
|
|
||||||
crontab.Start()
|
|
||||||
// 发送到微信
|
// 发送到微信
|
||||||
self.SendTextToGroup("叫啥好呢", "打卡程序启动成功!")
|
self.SendTextToGroup("叫啥好呢", "打卡程序启动成功!")
|
||||||
// 定时任务是另起协程执行的,这里使用 select 简答阻塞.实际开发中需要
|
|
||||||
// 根据实际情况进行控制
|
|
||||||
select {} //阻塞主线程停止
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SignInEnd(msg *openwechat.Message){
|
func SignInEnd(msg *openwechat.Message){
|
||||||
//关闭
|
|
||||||
defer crontab.Stop()
|
|
||||||
// 发送到微信
|
// 发送到微信
|
||||||
self.SendTextToGroup("group", "打卡程序结束运行成功!")
|
self.SendTextToGroup("group", "打卡程序结束运行成功!")
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user