@@ -58,8 +58,8 @@ type ConsumableDispatcher interface {
58
58
Consume (ctx context.Context ) error
59
59
}
60
60
61
- // Configuration is the struct for queue configs.
62
- type Configuration struct {
61
+ // configuration is the struct for queue configs.
62
+ type configuration struct {
63
63
RedisName string `yaml:"redisName" json:"redisName"`
64
64
Parallelism int `yaml:"parallelism" json:"parallelism"`
65
65
CheckQueueLengthIntervalSecond int `yaml:"checkQueueLengthIntervalSecond" json:"checkQueueLengthIntervalSecond"`
@@ -73,11 +73,8 @@ type makerIn struct {
73
73
JobDispatcher JobDispatcher `optional:"true"`
74
74
EventDispatcher contract.Dispatcher `optional:"true"`
75
75
Logger log.Logger
76
- AppName contract.AppName
77
- Env contract.Env
78
76
Gauge Gauge `optional:"true"`
79
77
Populator contract.DIPopulator `optional:"true"`
80
- Driver Driver `optional:"true"`
81
78
}
82
79
83
80
// makerOut is the di output JobFrom provideDispatcherFactory
@@ -99,7 +96,7 @@ func provideDispatcherFactory(option *providersOption) func(p makerIn) (makerOut
99
96
return func (p makerIn ) (makerOut , error ) {
100
97
var (
101
98
err error
102
- queueConfs map [string ]Configuration
99
+ queueConfs map [string ]configuration
103
100
)
104
101
err = p .Conf .Unmarshal ("queue" , & queueConfs )
105
102
if err != nil {
@@ -108,14 +105,14 @@ func provideDispatcherFactory(option *providersOption) func(p makerIn) (makerOut
108
105
factory := di .NewFactory (func (name string ) (di.Pair , error ) {
109
106
var (
110
107
ok bool
111
- conf Configuration
108
+ conf configuration
112
109
)
113
110
p := p
114
111
if conf , ok = queueConfs [name ]; ! ok {
115
112
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 )
117
114
}
118
- conf = Configuration {
115
+ conf = configuration {
119
116
Parallelism : runtime .NumCPU (),
120
117
CheckQueueLengthIntervalSecond : 0 ,
121
118
}
@@ -135,12 +132,8 @@ func provideDispatcherFactory(option *providersOption) func(p makerIn) (makerOut
135
132
var driver = option .driver
136
133
if option .driver == nil {
137
134
driver , err = option .driverConstructor (
138
- DriverConstructorArgs {
135
+ DriverArgs {
139
136
Name : name ,
140
- Conf : conf ,
141
- Logger : p .Logger ,
142
- AppName : p .AppName ,
143
- Env : p .Env ,
144
137
Populator : p .Populator ,
145
138
},
146
139
)
@@ -191,27 +184,41 @@ func (d makerOut) ProvideRunGroup(group *run.Group) {
191
184
}
192
185
}
193
186
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
+
196
198
if args .Populator == nil {
197
199
return nil , errors .New ("the default driver requires setting the populator in DI container" )
198
200
}
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 )
201
207
}
202
- client , err := maker .Make (args .Conf .RedisName )
208
+
209
+ client , err := injected .Maker .Make (redisName )
203
210
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 )
205
212
}
206
213
return & RedisDriver {
207
- Logger : args .Logger ,
214
+ Logger : injected .Logger ,
208
215
RedisClient : client ,
209
216
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 ),
215
222
},
216
223
}, nil
217
224
}
@@ -239,7 +246,7 @@ func provideConfig() configOut {
239
246
configs := []config.ExportedConfig {{
240
247
Owner : "queue" ,
241
248
Data : map [string ]interface {}{
242
- "queue" : map [string ]Configuration {
249
+ "queue" : map [string ]configuration {
243
250
"default" : {
244
251
RedisName : "default" ,
245
252
Parallelism : runtime .NumCPU (),
0 commit comments