mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
update cron example
This commit is contained in:
parent
2a59c59bae
commit
87cf65a213
@ -1,6 +1,6 @@
|
|||||||
.PHONY: dev
|
.PHONY: dev
|
||||||
dev:
|
dev:
|
||||||
wrangler dev
|
wrangler dev --test-scheduled
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
|
@ -18,3 +18,12 @@ make dev # run dev server
|
|||||||
make build # build Go Wasm binary
|
make build # build Go Wasm binary
|
||||||
make deploy # deploy worker
|
make deploy # deploy worker
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Testing cron schedule
|
||||||
|
|
||||||
|
* With curl command below, you can test the cron schedule.
|
||||||
|
- see: https://developers.cloudflare.com/workers/runtime-apis/handlers/scheduled/#background
|
||||||
|
|
||||||
|
```
|
||||||
|
curl "http://localhost:8787/__scheduled?cron=*+*+*+*+*"
|
||||||
|
```
|
||||||
|
@ -3,7 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/syumai/workers/cloudflare"
|
||||||
"github.com/syumai/workers/cloudflare/cron"
|
"github.com/syumai/workers/cloudflare/cron"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,6 +17,11 @@ func task(ctx context.Context) error {
|
|||||||
|
|
||||||
fmt.Println(e.ScheduledTime.Unix())
|
fmt.Println(e.ScheduledTime.Unix())
|
||||||
|
|
||||||
|
cloudflare.WaitUntil(func() {
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
fmt.Println("Run sub task after returning from main task")
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user