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

57 lines
942 B
Go
Raw Normal View History

2024-05-04 21:42:44 +00:00
{{- $pkg := env "PWD" | base | coalesce Package -}}
package {{$pkg}}
import (
"context"
2024-05-08 00:25:06 +00:00
"fmt"
2024-05-04 21:42:44 +00:00
"log/slog"
"reflect"
2024-05-08 00:25:06 +00:00
"gfx.cafe/util/go/fxriver"
2024-05-04 21:42:44 +00:00
"github.com/riverqueue/river"
"go.uber.org/fx"
)
var (
packageName = 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
2024-05-08 00:25:06 +00:00
Output fxriver.WorkConfigurer `group:"river_worker"`
2024-05-04 21:42:44 +00:00
}
func New(p Params) (r Result, err error) {
o := &Worker{}
o.log = p.Log
2024-05-08 00:25:06 +00:00
r.Output = fxriver.Wrap(o)
2024-05-04 21:42:44 +00:00
return
}
func (o *Worker) Work(ctx context.Context, job *river.Job[*Args]) error {
2024-05-08 01:35:22 +00:00
o.log.Info("Starting Job", "name", packageName, "args", job.Args)
return fmt.Errorf("Job %s is not implemented", packageName)
2024-05-04 21:42:44 +00:00
}