feat: add new job cmd

This commit is contained in:
Rogee
2025-01-16 09:21:33 +08:00
parent 57f8e95d50
commit 2e8366e7bf
4 changed files with 133 additions and 0 deletions

48
templates/jobs/job.go.tpl Normal file
View File

@@ -0,0 +1,48 @@
package jobs
import (
"context"
"time"
_ "git.ipao.vip/rogeecn/atom"
_ "git.ipao.vip/rogeecn/atom/contracts"
. "github.com/riverqueue/river"
)
var (
_ JobArgs = (*{{.Name}}Job)(nil)
_ JobArgsWithInsertOpts = (*{{.Name}}Job)(nil)
)
type {{.Name}}Job struct {
}
// InsertOpts implements JobArgsWithInsertOpts.
func (s {{.Name}}Job) InsertOpts() InsertOpts {
return InsertOpts{
Queue: QueueDefault,
Priority: PriorityDefault,
// UniqueOpts: UniqueOpts{
// ByArgs: true,
// },
}
}
func ({{.Name}}Job) Kind() string {
return "{{.Name}}Job"
}
var _ Worker[{{.Name}}Job] = (*{{.Name}}JobWorker)(nil)
// @provider(job)
type {{.Name}}JobWorker struct {
WorkerDefaults[{{.Name}}Job]
}
func (w *{{.Name}}JobWorker) NextRetry(job *Job[{{.Name}}Job]) time.Time {
return time.Now().Add(5 * time.Second)
}
func (w *{{.Name}}JobWorker) Work(ctx context.Context, job *Job[{{.Name}}Job]) error {
return nil
}

View File

@@ -13,3 +13,6 @@ var Provider embed.FS
//go:embed events
var Events embed.FS
//go:embed jobs
var Jobs embed.FS