gocron
v2.14.0

Gocron是一個工作調度軟件包,可讓您以預定的間隔運行GO函數。
如果您想聊天,可以在Slack上找到我們
go get github.com/go-co-op/gocron/v2
package main
import (
"fmt"
"time"
"github.com/go-co-op/gocron/v2"
)
func main () {
// create a scheduler
s , err := gocron . NewScheduler ()
if err != nil {
// handle error
}
// add a job to the scheduler
j , err := s . NewJob (
gocron . DurationJob (
10 * time . Second ,
),
gocron . NewTask (
func ( a string , b int ) {
// do things
},
"hello" ,
1 ,
),
)
if err != nil {
// handle error
}
// each job has a unique id
fmt . Println ( j . ID ())
// start the scheduler
s . Start ()
// block until you are ready to shut down
select {
case <- time . After ( time . Minute ):
}
// when you're done, shut it down
err = s . Shutdown ()
if err != nil {
// handle error
}
}作業可以以不同的間隔運行。
time.Duration運行。time.Duration進行作業。作業可以單獨或整個調度程序受到限制。
可以運行多個Gocron實例。
工作事件可以觸發動作。
提供許多工作和調度程序選項。
NewJob創建作業時可以設置作業選項。NewScheduler和WithGlobalJobOptions選項創建調度程序時,可以設置全局作業選項。NewScheduler創建調度程序時,可以設置調度程序選項。可以啟用日誌。
可以從每個作業的執行中收集指標。
Gocron庫設置為啟用測試。
我們感謝免費和開源軟件的支持!
該項目得到了支持:
噴氣橋
哨兵