mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
39 lines
675 B
Go
39 lines
675 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/syumai/workers"
|
|
"github.com/syumai/workers/cloudflare/cron"
|
|
)
|
|
|
|
func main() {
|
|
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
|
fmt.Fprint(w, "Hello, world!")
|
|
})
|
|
|
|
task := func(ctx context.Context) error {
|
|
e, err := cron.NewEvent(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println(e.ScheduledTime.Unix())
|
|
return nil
|
|
}
|
|
|
|
// set up the worker
|
|
workers.ServeNonBlock(handler)
|
|
cron.ScheduleTaskNonBlock(task)
|
|
|
|
// send a ready signal to the runtime
|
|
workers.Ready()
|
|
|
|
// block until the handler or task is done
|
|
select {
|
|
case <-workers.Done():
|
|
case <-cron.Done():
|
|
}
|
|
}
|