1 Star 0 Fork 0

Souki/go-framework

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
run_job_mix.go 1003 Bytes
Copy Edit Raw Blame History
王少奇 authored 2021-08-09 09:39 +08:00 . 优化
package main
import (
"gitee.com/scottq/go-framework/src/miscs"
v1job "gitee.com/scottq/go-framework/src/v1/jobserver"
"time"
)
func main() {
//第一个job(5秒后执行结束)
job := v1job.NewJob("printX", func() {
for i := 0; i <= 10; i++ {
println("job", i, time.Now().Format(miscs.DateTimeLayout))
time.Sleep(time.Millisecond * 500)
}
})
job.SetCoNum(2)
//第二个job(定时执行的,每秒执行)
sch := v1job.NewJobScheduler("scheduler", time.Second, v1job.NewJob("printX", func() {
println("scheduler", time.Now().Format(miscs.DateTimeLayout))
}))
runner := v1job.NewJobRunner("mixJobs")
runner.AddJob(job)
runner.AddJob(sch)
//只执行一次
runner.AddExecute("printTime", func() {
println("executor", time.Now().Format(miscs.DateTimeLayout))
})
//15秒后手动停止定时任务
go func() {
time.Sleep(time.Second * 15)
println("stop scheduler", time.Now().Format(miscs.DateTimeLayout))
sch.Stop()
}()
runner.Run()
println("end")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/scottq/go-framework.git
git@gitee.com:scottq/go-framework.git
scottq
go-framework
go-framework
v1.1.42

Search