mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
26 lines
465 B
Go
26 lines
465 B
Go
![]() |
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"time"
|
||
|
|
||
|
"github.com/syumai/workers/cloudflare/cron"
|
||
|
)
|
||
|
|
||
|
func task(ctx context.Context) error {
|
||
|
e, err := cron.NewEvent(ctx)
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("failed to create cron event: %w", err)
|
||
|
}
|
||
|
log.Printf("Cron job triggered at: %s", time.Unix(e.ScheduledTime.Unix(), 0).Format(time.RFC3339))
|
||
|
log.Println("Executing scheduled task...")
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
cron.ScheduleTask(task)
|
||
|
select {}
|
||
|
}
|