61 lines
862 B
Go
61 lines
862 B
Go
{{- $pkg := env "PWD" | base | coalesce Package -}}
|
|
package {{$pkg}}
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"reflect"
|
|
|
|
"github.com/riverqueue/river"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
var (
|
|
packageName = reflect.TypeOf(Args{}).PkgPath()
|
|
)
|
|
|
|
type Args struct {
|
|
Block int
|
|
Force bool
|
|
}
|
|
|
|
func (a *Args) Kind() string {
|
|
return packageName + ".task"
|
|
}
|
|
|
|
type Worker struct {
|
|
river.WorkerDefaults[*Args]
|
|
|
|
log *slog.Logger
|
|
}
|
|
type Params struct {
|
|
fx.In
|
|
|
|
Workers *river.Workers
|
|
Ctx context.Context
|
|
Lc fx.Lifecycle
|
|
Log *slog.Logger
|
|
}
|
|
|
|
type Result struct {
|
|
fx.Out
|
|
|
|
Output *Worker
|
|
}
|
|
|
|
func New(p Params) (r Result, err error) {
|
|
o := &Worker{}
|
|
o.log = p.Log
|
|
|
|
err = river.AddWorkerSafely(p.Workers, o)
|
|
if err != nil {
|
|
return
|
|
}
|
|
r.Output = o
|
|
return
|
|
}
|
|
|
|
func (o *Worker) Work(ctx context.Context, job *river.Job[*Args]) error {
|
|
return nil
|
|
}
|