2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2019-01-16 22:59:26 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2019-01-16 22:59:26 +08:00
|
|
|
|
|
|
|
package gcron_test
|
|
|
|
|
|
|
|
import (
|
2021-09-28 19:04:36 +08:00
|
|
|
"context"
|
2019-06-19 09:06:52 +08:00
|
|
|
"time"
|
2019-07-29 21:01:19 +08:00
|
|
|
|
2021-10-11 21:41:56 +08:00
|
|
|
"github.com/gogf/gf/v2/os/gcron"
|
|
|
|
"github.com/gogf/gf/v2/os/glog"
|
2019-01-16 22:59:26 +08:00
|
|
|
)
|
|
|
|
|
2020-03-22 12:49:46 +08:00
|
|
|
func Example_cronAddSingleton() {
|
2021-10-30 15:36:10 +08:00
|
|
|
gcron.AddSingleton(ctx, "* * * * * *", func(ctx context.Context) {
|
2021-09-28 19:04:36 +08:00
|
|
|
glog.Println(context.TODO(), "doing")
|
2019-06-19 09:06:52 +08:00
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
})
|
|
|
|
select {}
|
2019-01-16 22:59:26 +08:00
|
|
|
}
|