Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 1006 Bytes

README.md

File metadata and controls

45 lines (33 loc) · 1006 Bytes

Boomerang 🪃

Simple distributed recurring task schedule for golang implemented on top of redis.

Test

Usage

package main

import (
    "context"
    "fmt"
    "time"

    "github.com/redis/go-redis/redis/v9"
    "github.com/opsway-io/boomerang"
)

func main() {
    ctx := context.Background()

    cli := redis.NewClient(&redis.Options{
        Addr: "localhost:6379",
    })

    sch := boomerang.NewSchedule(cli)

    task := boomerang.NewTask(
        "greeter",
        "some-unique-id",
        []byte("Hello!"),
    )

    // Schedule task for execution every second starting from now
    if err := sch.Add(ctx, task, time.Second, time.Now()); err != nil {
        panic(err)
    }

    sch.On(ctx, "greeter", func(ctx context.Context, task *boomerang.Task) {
        fmt.Printf("%s\n", task.Data)
    })
}