mirror of
https://github.com/acaloiaro/neoq
synced 2026-07-21 10:12:18 +00:00
33 lines
632 B
Go
33 lines
632 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/acaloiaro/neoq"
|
|
"github.com/acaloiaro/neoq/backends/memory"
|
|
"github.com/acaloiaro/neoq/handler"
|
|
)
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
nq, err := neoq.New(ctx, neoq.WithBackend(memory.Backend))
|
|
if err != nil {
|
|
log.Fatalf("error initializing neoq: %v", err)
|
|
}
|
|
|
|
// run a job periodically
|
|
h := handler.New(func(ctx context.Context) (err error) {
|
|
log.Println("running periodic job")
|
|
return
|
|
})
|
|
h.WithOptions(
|
|
handler.JobTimeout(500*time.Millisecond),
|
|
handler.Concurrency(1),
|
|
)
|
|
|
|
nq.StartCron(ctx, "* * * * * *", h)
|
|
|
|
time.Sleep(5 * time.Second)
|
|
}
|