2023-04-30 10:35:04 +09:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2024-11-08 02:16:35 +09:00
|
|
|
"time"
|
2023-04-30 10:35:04 +09:00
|
|
|
|
2024-11-08 02:16:35 +09:00
|
|
|
"github.com/syumai/workers/cloudflare"
|
2023-04-30 10:54:24 +09:00
|
|
|
"github.com/syumai/workers/cloudflare/cron"
|
2023-04-30 10:35:04 +09:00
|
|
|
)
|
|
|
|
|
2024-01-22 22:06:54 +09:00
|
|
|
func task(ctx context.Context) error {
|
|
|
|
e, err := cron.NewEvent(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-04-30 10:35:04 +09:00
|
|
|
}
|
|
|
|
|
2024-01-22 22:06:54 +09:00
|
|
|
fmt.Println(e.ScheduledTime.Unix())
|
|
|
|
|
2024-11-08 02:16:35 +09:00
|
|
|
cloudflare.WaitUntil(func() {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
fmt.Println("Run sub task after returning from main task")
|
|
|
|
})
|
|
|
|
|
2023-04-30 10:35:04 +09:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2023-04-30 10:54:24 +09:00
|
|
|
cron.ScheduleTask(task)
|
2023-04-30 10:35:04 +09:00
|
|
|
}
|