feat: update

This commit is contained in:
Rogee
2025-09-10 18:06:24 +08:00
parent 66deb69c32
commit 1306a5bec0
4 changed files with 16 additions and 20 deletions

View File

@@ -42,3 +42,5 @@ init: tools
@atomctl gen provider @atomctl gen provider
@buf generate @buf generate
@go mod tidy @go mod tidy
@go get -u
@go mod tidy

View File

@@ -40,14 +40,14 @@ func (w *DemoJobWorker) NextRetry(job *Job[DemoJob]) time.Time {
} }
func (w *DemoJobWorker) Work(ctx context.Context, job *Job[DemoJob]) error { func (w *DemoJobWorker) Work(ctx context.Context, job *Job[DemoJob]) error {
log = log.WithField("job", job.Kind()) logger := log.WithField("job", job.Args.Kind())
log.Infof("[START] %s args: %v", job.Kind(), job.Args.Strings) logger.Infof("[START] %s args: %v", job.Args.Kind(), job.Args.Strings)
defer log.Infof("[END] %s", job.Kind()) defer logger.Infof("[END] %s", job.Args.Kind())
// modify below // modify below
sort.Strings(job.Args.Strings) sort.Strings(job.Args.Strings)
log.Infof("[%s] Sorted strings: %v\n", time.Now().Format(time.TimeOnly), job.Args.Strings) logger.Infof("[%s] Sorted strings: %v\n", time.Now().Format(time.TimeOnly), job.Args.Strings)
return nil return nil
} }

View File

@@ -4,10 +4,8 @@ import (
"context" "context"
"testing" "testing"
"{{.ModuleName}}/app/srv/services" "{{.ModuleName}}/app/services"
"{{.ModuleName}}/app/srv/testx" "{{.ModuleName}}/app/srv/testx"
"{{.ModuleName}}/providers/app"
"{{.ModuleName}}/providers/job"
. "github.com/riverqueue/river" . "github.com/riverqueue/river"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
@@ -21,8 +19,6 @@ type DemoJobSuiteInjectParams struct {
dig.In dig.In
Initials []contracts.Initial `group:"initials"` // nolint:structcheck Initials []contracts.Initial `group:"initials"` // nolint:structcheck
Job *job.Job
App *app.Config
} }
type DemoJobSuite struct { type DemoJobSuite struct {
@@ -48,10 +44,7 @@ func (t *DemoJobSuite) Test_Work() {
}, },
} }
worker := &DemoJobWorker{ worker := &DemoJobWorker{}
job: t.Job,
app: t.App,
}
err := worker.Work(context.Background(), job) err := worker.Work(context.Background(), job)
So(err, ShouldBeNil) So(err, ShouldBeNil)

View File

@@ -33,13 +33,6 @@ type Service struct {
func (svc *Service) listenerConfig() fiber.ListenConfig { func (svc *Service) listenerConfig() fiber.ListenConfig {
listenConfig := fiber.ListenConfig{ listenConfig := fiber.ListenConfig{
EnablePrintRoutes: true, EnablePrintRoutes: true,
OnShutdownSuccess: func() {
log.Info("http server shutdown success")
},
OnShutdownError: func(err error) {
log.Error("http server shutdown error: ", err)
},
// DisableStartupMessage: true, // DisableStartupMessage: true,
} }
@@ -92,6 +85,14 @@ func Provide(opts ...opt.Option) error {
TimeZone: "Asia/Shanghai", TimeZone: "Asia/Shanghai",
})) }))
engine.Hooks().OnPostShutdown(func(err error) error {
if err != nil {
log.Error("http server shutdown error: ", err)
}
log.Info("http server has shutdown success")
return nil
})
return &Service{ return &Service{
Engine: engine, Engine: engine,
conf: &config, conf: &config,