home/private_dot_config/boilr/templates/river/template/job.go

58 lines
961 B
Go

{{- $pkg := env "PWD" | base | coalesce Package -}}
package {{$pkg}}
import (
"context"
"fmt"
"log/slog"
"path"
"reflect"
"gfx.cafe/util/go/fxriver"
"github.com/riverqueue/river"
"go.uber.org/fx"
)
var (
packageName = path.Base(reflect.TypeOf(Args{}).PkgPath())
)
type Args struct {
}
func (a *Args) Kind() string {
return packageName + ".task"
}
type Worker struct {
river.WorkerDefaults[*Args]
log *slog.Logger
}
type Params struct {
fx.In
Ctx context.Context
Lc fx.Lifecycle
Log *slog.Logger
}
type Result struct {
fx.Out
Output fxriver.WorkConfigurer `group:"river_worker"`
}
func New(p Params) (r Result, err error) {
o := &Worker{}
o.log = p.Log
r.Output = fxriver.Wrap(o)
return
}
func (o *Worker) Work(ctx context.Context, job *river.Job[*Args]) error {
o.log.Info("Starting Job", "name", packageName, "args", job.Args)
return fmt.Errorf("Job %s is not implemented", packageName)
}