@@ -58,8 +58,8 @@ type ConsumableDispatcher interface {
5858 Consume (ctx context.Context ) error
5959}
6060
61- // Configuration is the struct for queue configs.
62- type Configuration struct {
61+ // configuration is the struct for queue configs.
62+ type configuration struct {
6363 RedisName string `yaml:"redisName" json:"redisName"`
6464 Parallelism int `yaml:"parallelism" json:"parallelism"`
6565 CheckQueueLengthIntervalSecond int `yaml:"checkQueueLengthIntervalSecond" json:"checkQueueLengthIntervalSecond"`
@@ -73,11 +73,8 @@ type makerIn struct {
7373 JobDispatcher JobDispatcher `optional:"true"`
7474 EventDispatcher contract.Dispatcher `optional:"true"`
7575 Logger log.Logger
76- AppName contract.AppName
77- Env contract.Env
7876 Gauge Gauge `optional:"true"`
7977 Populator contract.DIPopulator `optional:"true"`
80- Driver Driver `optional:"true"`
8178}
8279
8380// makerOut is the di output JobFrom provideDispatcherFactory
@@ -99,7 +96,7 @@ func provideDispatcherFactory(option *providersOption) func(p makerIn) (makerOut
9996 return func (p makerIn ) (makerOut , error ) {
10097 var (
10198 err error
102- queueConfs map [string ]Configuration
99+ queueConfs map [string ]configuration
103100 )
104101 err = p .Conf .Unmarshal ("queue" , & queueConfs )
105102 if err != nil {
@@ -108,14 +105,14 @@ func provideDispatcherFactory(option *providersOption) func(p makerIn) (makerOut
108105 factory := di .NewFactory (func (name string ) (di.Pair , error ) {
109106 var (
110107 ok bool
111- conf Configuration
108+ conf configuration
112109 )
113110 p := p
114111 if conf , ok = queueConfs [name ]; ! ok {
115112 if name != "default" {
116- return di.Pair {}, fmt .Errorf ("queue Configuration %s not found" , name )
113+ return di.Pair {}, fmt .Errorf ("queue configuration %s not found" , name )
117114 }
118- conf = Configuration {
115+ conf = configuration {
119116 Parallelism : runtime .NumCPU (),
120117 CheckQueueLengthIntervalSecond : 0 ,
121118 }
@@ -135,12 +132,8 @@ func provideDispatcherFactory(option *providersOption) func(p makerIn) (makerOut
135132 var driver = option .driver
136133 if option .driver == nil {
137134 driver , err = option .driverConstructor (
138- DriverConstructorArgs {
135+ DriverArgs {
139136 Name : name ,
140- Conf : conf ,
141- Logger : p .Logger ,
142- AppName : p .AppName ,
143- Env : p .Env ,
144137 Populator : p .Populator ,
145138 },
146139 )
@@ -191,27 +184,41 @@ func (d makerOut) ProvideRunGroup(group *run.Group) {
191184 }
192185}
193186
194- func newDefaultDriver (args DriverConstructorArgs ) (Driver , error ) {
195- var maker otredis.Maker
187+ func newDefaultDriver (args DriverArgs ) (Driver , error ) {
188+ var injected struct {
189+ di.In
190+
191+ contract.AppName
192+ contract.Env
193+ contract.Logger
194+ otredis.Maker
195+ contract.ConfigUnmarshaler
196+ }
197+
196198 if args .Populator == nil {
197199 return nil , errors .New ("the default driver requires setting the populator in DI container" )
198200 }
199- if err := args .Populator .Populate (& maker ); err != nil {
200- return nil , fmt .Errorf ("the default driver requires an otredis.Maker in DI container: %w" , err )
201+ if err := args .Populator .Populate (& injected ); err != nil {
202+ return nil , fmt .Errorf ("missing dependency for the default queue driver: %w" , err )
203+ }
204+ var redisName string
205+ if err := injected .ConfigUnmarshaler .Unmarshal (fmt .Sprintf ("queue.%s.redisName" , injected .AppName ), & redisName ); err != nil {
206+ return nil , fmt .Errorf ("bad configuration: %w" , err )
201207 }
202- client , err := maker .Make (args .Conf .RedisName )
208+
209+ client , err := injected .Maker .Make (redisName )
203210 if err != nil {
204- return nil , fmt .Errorf ("the default driver requires the redis client called %s: %w" , args . Conf . RedisName , err )
211+ return nil , fmt .Errorf ("the default driver requires the redis client called %s: %w" , redisName , err )
205212 }
206213 return & RedisDriver {
207- Logger : args .Logger ,
214+ Logger : injected .Logger ,
208215 RedisClient : client ,
209216 ChannelConfig : ChannelConfig {
210- Delayed : fmt .Sprintf ("{%s:%s:%s}:delayed" , args .AppName .String (), args .Env .String (), args .Name ),
211- Failed : fmt .Sprintf ("{%s:%s:%s}:failed" , args .AppName .String (), args .Env .String (), args .Name ),
212- Reserved : fmt .Sprintf ("{%s:%s:%s}:reserved" , args .AppName .String (), args .Env .String (), args .Name ),
213- Waiting : fmt .Sprintf ("{%s:%s:%s}:waiting" , args .AppName .String (), args .Env .String (), args .Name ),
214- Timeout : fmt .Sprintf ("{%s:%s:%s}:timeout" , args .AppName .String (), args .Env .String (), args .Name ),
217+ Delayed : fmt .Sprintf ("{%s:%s:%s}:delayed" , injected .AppName .String (), injected .Env .String (), args .Name ),
218+ Failed : fmt .Sprintf ("{%s:%s:%s}:failed" , injected .AppName .String (), injected .Env .String (), args .Name ),
219+ Reserved : fmt .Sprintf ("{%s:%s:%s}:reserved" , injected .AppName .String (), injected .Env .String (), args .Name ),
220+ Waiting : fmt .Sprintf ("{%s:%s:%s}:waiting" , injected .AppName .String (), injected .Env .String (), args .Name ),
221+ Timeout : fmt .Sprintf ("{%s:%s:%s}:timeout" , injected .AppName .String (), injected .Env .String (), args .Name ),
215222 },
216223 }, nil
217224}
@@ -239,7 +246,7 @@ func provideConfig() configOut {
239246 configs := []config.ExportedConfig {{
240247 Owner : "queue" ,
241248 Data : map [string ]interface {}{
242- "queue" : map [string ]Configuration {
249+ "queue" : map [string ]configuration {
243250 "default" : {
244251 RedisName : "default" ,
245252 Parallelism : runtime .NumCPU (),
0 commit comments