Forráskód Böngészése

wip:cron 定时任务提交

wangkaiyue 2 éve
szülő
commit
3ad8cc0d62
3 módosított fájl, 53 hozzáadás és 0 törlés
  1. 3 0
      config.yaml
  2. 28 0
      go.mod
  3. 22 0
      main.go

+ 3 - 0
config.yaml

@@ -0,0 +1,3 @@
+cron: "*/5 * * * * *"
+curlAddr: ""
+

+ 28 - 0
go.mod

@@ -0,0 +1,28 @@
+module elasticsearch_status
+
+go 1.19
+
+require github.com/gogf/gf/v2 v2.5.0
+
+require (
+	github.com/BurntSushi/toml v1.1.0 // indirect
+	github.com/clbanning/mxj/v2 v2.5.5 // indirect
+	github.com/fatih/color v1.13.0 // indirect
+	github.com/fsnotify/fsnotify v1.5.4 // indirect
+	github.com/go-logr/logr v1.2.3 // indirect
+	github.com/go-logr/stdr v1.2.2 // indirect
+	github.com/gorilla/websocket v1.5.0 // indirect
+	github.com/grokify/html-strip-tags-go v0.0.1 // indirect
+	github.com/magiconair/properties v1.8.6 // indirect
+	github.com/mattn/go-colorable v0.1.9 // indirect
+	github.com/mattn/go-isatty v0.0.14 // indirect
+	github.com/mattn/go-runewidth v0.0.9 // indirect
+	github.com/olekukonko/tablewriter v0.0.5 // indirect
+	go.opentelemetry.io/otel v1.7.0 // indirect
+	go.opentelemetry.io/otel/sdk v1.7.0 // indirect
+	go.opentelemetry.io/otel/trace v1.7.0 // indirect
+	golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
+	golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
+	golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect
+	gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
+)

+ 22 - 0
main.go

@@ -0,0 +1,22 @@
+package main
+
+import (
+	"context"
+	"fmt"
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/os/gcron"
+	"github.com/gogf/gf/v2/os/gctx"
+	"time"
+)
+
+func main() {
+	ctx := gctx.New()
+	e, err := gcron.New().Add(ctx, g.Cfg().MustGet(ctx, "cron").String(), func(ctx context.Context) {
+		fmt.Println("cc", time.Now().Unix())
+	})
+	if err != nil {
+		panic(err)
+	}
+	e.Start()
+	select {}
+}