@@ -39,8 +39,12 @@ var Queue = QueueSettings{}
3939
4040// GetQueueSettings returns the queue settings for the appropriately named queue
4141func GetQueueSettings (name string ) QueueSettings {
42+ return getQueueSettings (Cfg , name )
43+ }
44+
45+ func getQueueSettings (rootCfg Config , name string ) QueueSettings {
4246 q := QueueSettings {}
43- sec := Cfg .Section ("queue." + name )
47+ sec := rootCfg .Section ("queue." + name )
4448 q .Name = name
4549
4650 // DataDir is not directly inheritable
@@ -85,7 +89,11 @@ func GetQueueSettings(name string) QueueSettings {
8589// ParseQueueSettings sets up the default settings for Queues
8690// This is exported for tests to be able to use the queue
8791func ParseQueueSettings () {
88- sec := Cfg .Section ("queue" )
92+ parseQueueSettings (Cfg )
93+ }
94+
95+ func parseQueueSettings (rootCfg Config ) {
96+ sec := rootCfg .Section ("queue" )
8997 Queue .DataDir = filepath .ToSlash (sec .Key ("DATADIR" ).MustString ("queues/" ))
9098 if ! filepath .IsAbs (Queue .DataDir ) {
9199 Queue .DataDir = filepath .ToSlash (filepath .Join (AppDataPath , Queue .DataDir ))
@@ -108,10 +116,10 @@ func ParseQueueSettings() {
108116
109117 // Now handle the old issue_indexer configuration
110118 // FIXME: DEPRECATED to be removed in v1.18.0
111- section := Cfg .Section ("queue.issue_indexer" )
119+ section := rootCfg .Section ("queue.issue_indexer" )
112120 directlySet := toDirectlySetKeysSet (section )
113121 if ! directlySet .Contains ("TYPE" ) && defaultType == "" {
114- switch typ := Cfg .Section ("indexer" ).Key ("ISSUE_INDEXER_QUEUE_TYPE" ).MustString ("" ); typ {
122+ switch typ := rootCfg .Section ("indexer" ).Key ("ISSUE_INDEXER_QUEUE_TYPE" ).MustString ("" ); typ {
115123 case "levelqueue" :
116124 _ , _ = section .NewKey ("TYPE" , "level" )
117125 case "channel" :
@@ -125,25 +133,25 @@ func ParseQueueSettings() {
125133 }
126134 }
127135 if ! directlySet .Contains ("LENGTH" ) {
128- length := Cfg .Section ("indexer" ).Key ("UPDATE_BUFFER_LEN" ).MustInt (0 )
136+ length := rootCfg .Section ("indexer" ).Key ("UPDATE_BUFFER_LEN" ).MustInt (0 )
129137 if length != 0 {
130138 _ , _ = section .NewKey ("LENGTH" , strconv .Itoa (length ))
131139 }
132140 }
133141 if ! directlySet .Contains ("BATCH_LENGTH" ) {
134- fallback := Cfg .Section ("indexer" ).Key ("ISSUE_INDEXER_QUEUE_BATCH_NUMBER" ).MustInt (0 )
142+ fallback := rootCfg .Section ("indexer" ).Key ("ISSUE_INDEXER_QUEUE_BATCH_NUMBER" ).MustInt (0 )
135143 if fallback != 0 {
136144 _ , _ = section .NewKey ("BATCH_LENGTH" , strconv .Itoa (fallback ))
137145 }
138146 }
139147 if ! directlySet .Contains ("DATADIR" ) {
140- queueDir := filepath .ToSlash (Cfg .Section ("indexer" ).Key ("ISSUE_INDEXER_QUEUE_DIR" ).MustString ("" ))
148+ queueDir := filepath .ToSlash (rootCfg .Section ("indexer" ).Key ("ISSUE_INDEXER_QUEUE_DIR" ).MustString ("" ))
141149 if queueDir != "" {
142150 _ , _ = section .NewKey ("DATADIR" , queueDir )
143151 }
144152 }
145153 if ! directlySet .Contains ("CONN_STR" ) {
146- connStr := Cfg .Section ("indexer" ).Key ("ISSUE_INDEXER_QUEUE_CONN_STR" ).MustString ("" )
154+ connStr := rootCfg .Section ("indexer" ).Key ("ISSUE_INDEXER_QUEUE_CONN_STR" ).MustString ("" )
147155 if connStr != "" {
148156 _ , _ = section .NewKey ("CONN_STR" , connStr )
149157 }
@@ -153,31 +161,31 @@ func ParseQueueSettings() {
153161 // - will need to set default for [queue.*)] LENGTH appropriately though though
154162
155163 // Handle the old mailer configuration
156- handleOldLengthConfiguration ("mailer" , "mailer" , "SEND_BUFFER_LEN" , 100 )
164+ handleOldLengthConfiguration (rootCfg , "mailer" , "mailer" , "SEND_BUFFER_LEN" , 100 )
157165
158166 // Handle the old test pull requests configuration
159167 // Please note this will be a unique queue
160- handleOldLengthConfiguration ("pr_patch_checker" , "repository" , "PULL_REQUEST_QUEUE_LENGTH" , 1000 )
168+ handleOldLengthConfiguration (rootCfg , "pr_patch_checker" , "repository" , "PULL_REQUEST_QUEUE_LENGTH" , 1000 )
161169
162170 // Handle the old mirror queue configuration
163171 // Please note this will be a unique queue
164- handleOldLengthConfiguration ("mirror" , "repository" , "MIRROR_QUEUE_LENGTH" , 1000 )
172+ handleOldLengthConfiguration (rootCfg , "mirror" , "repository" , "MIRROR_QUEUE_LENGTH" , 1000 )
165173}
166174
167175// handleOldLengthConfiguration allows fallback to older configuration. `[queue.name]` `LENGTH` will override this configuration, but
168176// if that is left unset then we should fallback to the older configuration. (Except where the new length woul be <=0)
169- func handleOldLengthConfiguration (queueName , oldSection , oldKey string , defaultValue int ) {
170- if Cfg .Section (oldSection ).HasKey (oldKey ) {
177+ func handleOldLengthConfiguration (rootCfg Config , queueName , oldSection , oldKey string , defaultValue int ) {
178+ if rootCfg .Section (oldSection ).HasKey (oldKey ) {
171179 log .Error ("Deprecated fallback for %s queue length `[%s]` `%s` present. Use `[queue.%s]` `LENGTH`. This will be removed in v1.18.0" , queueName , queueName , oldSection , oldKey )
172180 }
173- value := Cfg .Section (oldSection ).Key (oldKey ).MustInt (defaultValue )
181+ value := rootCfg .Section (oldSection ).Key (oldKey ).MustInt (defaultValue )
174182
175183 // Don't override with 0
176184 if value <= 0 {
177185 return
178186 }
179187
180- section := Cfg .Section ("queue." + queueName )
188+ section := rootCfg .Section ("queue." + queueName )
181189 directlySet := toDirectlySetKeysSet (section )
182190 if ! directlySet .Contains ("LENGTH" ) {
183191 _ , _ = section .NewKey ("LENGTH" , strconv .Itoa (value ))
0 commit comments