feat: 使用 errgroup 并发处理 HTTP 服务和作业启动
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"go.ipao.vip/atom/container"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
|
||||
"github.com/go-pay/errgroup"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/middleware/favicon"
|
||||
"github.com/rogeecn/fabfile"
|
||||
@@ -93,8 +94,24 @@ func Serve(cmd *cobra.Command, args []string) error {
|
||||
svc.Http.Engine.Get("/admin*", checkStaticFile(svc.App.DistAdmin))
|
||||
svc.Http.Engine.Get("/*", checkStaticFile(svc.App.DistWeChat))
|
||||
|
||||
var eg errgroup.Group
|
||||
|
||||
eg.Go(func(ctx context.Context) error {
|
||||
// river job
|
||||
if err := svc.Job.Start(ctx); err != nil {
|
||||
log.WithError(err).Error("job start failed")
|
||||
return err
|
||||
}
|
||||
defer svc.Job.StopAndCancel(ctx)
|
||||
return nil
|
||||
})
|
||||
|
||||
eg.Go(func(ctx context.Context) error {
|
||||
return svc.Http.Serve(ctx)
|
||||
})
|
||||
|
||||
return eg.Wait()
|
||||
})
|
||||
}
|
||||
|
||||
func checkStaticFile(rootPath string) func(ctx fiber.Ctx) error {
|
||||
|
||||
Reference in New Issue
Block a user