github.com/wfusion/gofusion@v1.1.14/http/asynq.go (about)

     1  package http
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/gin-gonic/gin"
     7  	"github.com/pkg/errors"
     8  
     9  	"github.com/wfusion/gofusion/common/infra/asynq/asynqmon"
    10  	"github.com/wfusion/gofusion/redis"
    11  
    12  	rdsDrv "github.com/redis/go-redis/v9"
    13  )
    14  
    15  func initAsynq(ctx context.Context, appName string, r IRouter, confs []asynqConf) {
    16  	if len(confs) == 0 || r == nil {
    17  		return
    18  	}
    19  
    20  	for _, conf := range confs {
    21  		switch conf.InstanceType {
    22  		case instanceTypeRedis:
    23  		default:
    24  			panic(errors.Errorf("unknown asynq instance type: %+v", conf.InstanceType))
    25  		}
    26  		connOpt := &asynqRedisConnOpt{UniversalClient: redis.Use(ctx, conf.Instance, redis.AppName(appName))}
    27  		h := asynqmon.New(asynqmon.Options{
    28  			RootPath:          conf.Path,
    29  			RedisConnOpt:      connOpt,
    30  			PayloadFormatter:  nil,
    31  			ResultFormatter:   nil,
    32  			PrometheusAddress: conf.PrometheusAddress,
    33  			ReadOnly:          conf.Readonly,
    34  		})
    35  
    36  		r.Any(h.RootPath()+"/*any", gin.WrapH(h))
    37  	}
    38  }
    39  
    40  type asynqRedisConnOpt struct{ rdsDrv.UniversalClient }
    41  
    42  func (a *asynqRedisConnOpt) MakeRedisClient() any { return a.UniversalClient }