fix: issues

This commit is contained in:
rogeecn
2025-03-21 19:25:58 +08:00
parent e51acee8d8
commit 0015e2eee2
4 changed files with 17 additions and 41 deletions

View File

@@ -45,9 +45,7 @@ func Provide(opts ...opt.Option) error {
{{- end }} {{- end }}
{{ if eq .Mode "cronjob" }} {{ if eq .Mode "cronjob" }}
if _, err := __job.AddPeriodicJobs(obj); err != nil { container.Later(func() error { return __job.AddPeriodicJobs(obj) })
return nil, err
}
{{- end}} {{- end}}
return obj, nil return obj, nil

View File

@@ -4,21 +4,16 @@ import (
"context" "context"
"time" "time"
_ "go.ipao.vip/atom"
_ "go.ipao.vip/atom/contracts"
. "github.com/riverqueue/river" . "github.com/riverqueue/river"
_ "go.ipao.vip/atom"
"go.ipao.vip/atom/contracts"
) )
var ( var _ contracts.JobArgs = (*{{.Name}})(nil)
_ JobArgs = (*{{.Name}}Job)(nil)
_ JobArgsWithInsertOpts = (*{{.Name}}Job)(nil)
)
type {{.Name}}Job struct { type {{.Name}} struct {}
}
// InsertOpts implements JobArgsWithInsertOpts. func (s {{.Name}}) InsertOpts() InsertOpts {
func (s {{.Name}}Job) InsertOpts() InsertOpts {
return InsertOpts{ return InsertOpts{
Queue: QueueDefault, Queue: QueueDefault,
Priority: PriorityDefault, Priority: PriorityDefault,
@@ -28,21 +23,20 @@ func (s {{.Name}}Job) InsertOpts() InsertOpts {
} }
} }
func ({{.Name}}Job) Kind() string { func ({{.Name}}) Kind() string { return "{{.Name}}" }
return "{{.Name}}Job" func (arg {{.Name}}) UniqueID() string { return arg.Kind()}
}
var _ Worker[{{.Name}}Job] = (*{{.Name}}JobWorker)(nil) var _ Worker[{{.Name}}] = (*{{.Name}}Worker)(nil)
// @provider(job) // @provider(job)
type {{.Name}}JobWorker struct { type {{.Name}}Worker struct {
WorkerDefaults[{{.Name}}Job] WorkerDefaults[{{.Name}}]
} }
func (w *{{.Name}}JobWorker) NextRetry(job *Job[{{.Name}}Job]) time.Time { func (w *{{.Name}}Worker) NextRetry(job *Job[{{.Name}}]) time.Time {
return time.Now().Add(5 * time.Second) return time.Now().Add(5 * time.Second)
} }
func (w *{{.Name}}JobWorker) Work(ctx context.Context, job *Job[{{.Name}}Job]) error { func (w *{{.Name}}Worker) Work(ctx context.Context, job *Job[{{.Name}}]) error {
return nil return nil
} }

View File

@@ -8,13 +8,11 @@ import (
. "github.com/riverqueue/river" . "github.com/riverqueue/river"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
_ "go.ipao.vip/atom" _ "go.ipao.vip/atom"
"go.ipao.vip/atom/contracts"
_ "go.ipao.vip/atom/contracts" _ "go.ipao.vip/atom/contracts"
) )
var ( var _ contracts.JobArgs = SortArgs{}
_ JobArgs = SortArgs{}
_ JobArgsWithInsertOpts = SortArgs{}
)
type SortArgs struct { type SortArgs struct {
Strings []string `json:"strings"` Strings []string `json:"strings"`
@@ -27,9 +25,8 @@ func (s SortArgs) InsertOpts() InsertOpts {
} }
} }
func (SortArgs) Kind() string { func (SortArgs) Kind() string { return "sort" }
return "sort" func (a SortArgs) UniqueID() string { return a.Kind() }
}
var _ Worker[SortArgs] = (*SortWorker)(nil) var _ Worker[SortArgs] = (*SortWorker)(nil)

View File

@@ -2,7 +2,6 @@ package job
import ( import (
"context" "context"
"quyun/providers/postgres"
"sync" "sync"
"{{.ModuleName}}/providers/postgres" "{{.ModuleName}}/providers/postgres"
@@ -18,18 +17,6 @@ import (
"go.ipao.vip/atom/container" "go.ipao.vip/atom/container"
"go.ipao.vip/atom/contracts" "go.ipao.vip/atom/contracts"
"go.ipao.vip/atom/opt" "go.ipao.vip/atom/opt"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/pkg/errors"
"github.com/riverqueue/river"
"github.com/riverqueue/river/riverdriver/riverpgxv5"
"github.com/riverqueue/river/rivertype"
"github.com/samber/lo"
log "github.com/sirupsen/logrus"
"go.ipao.vip/atom/container"
"go.ipao.vip/atom/contracts"
"go.ipao.vip/atom/opt"
) )
func Provide(opts ...opt.Option) error { func Provide(opts ...opt.Option) error {