@@ -364,47 +364,31 @@ func updateConfigs(w http.ResponseWriter, r *http.Request) {
364
364
}
365
365
366
366
func updateGeoDatabases (w http.ResponseWriter , r * http.Request ) {
367
- updateNotification := make (chan struct {})
368
- errorChannel := make (chan error , 1 )
369
- done := make (chan struct {})
370
- defer func () {
371
- close (updateNotification )
372
- close (errorChannel )
373
- }()
374
-
375
- go func () {
376
- defer close (done )
377
- for {
378
- select {
379
- case <- updateNotification :
380
- cfg , err := executor .ParseWithPath (C .Path .Config ())
381
- if err != nil {
382
- log .Errorln ("[REST-API] update GEO databases failed: %v" , err )
383
- render .Status (r , http .StatusInternalServerError )
384
- render .JSON (w , r , newError ("Error parsing configuration" ))
385
- return
386
- }
387
-
388
- log .Warnln ("[REST-API] update GEO databases success, applying config" )
389
- executor .ApplyConfig (cfg , false )
390
- return
391
- case err := <- errorChannel :
392
- log .Errorln ("[REST-API] update GEO databases failed: %v" , err )
393
- render .Status (r , http .StatusInternalServerError )
394
- render .JSON (w , r , err .Error ())
395
- return
396
- }
397
- }
398
- }()
399
-
400
- go func () {
401
- err := updater .UpdateGeoDatabases (updateNotification )
367
+ if updater .UpdatingGeo .Load () {
368
+ render .Status (r , http .StatusConflict )
369
+ render .JSON (w , r , newError ("GEO database is updating, skip" ))
370
+ return
371
+ }
372
+
373
+ onSuccess := func () {
374
+ cfg , err := executor .ParseWithPath (C .Path .Config ())
402
375
if err != nil {
403
- errorChannel <- err
376
+ log .Errorln ("[GEO] update GEO databases failed: %v" , err )
377
+ return
404
378
}
405
- }()
406
379
407
- <- done
380
+ log .Warnln ("[GEO] update GEO databases success, applying config" )
381
+
382
+ executor .ApplyConfig (cfg , false )
383
+ }
384
+
385
+ err := updater .UpdateGeoDatabases (onSuccess )
386
+ if err != nil {
387
+ render .Status (r , http .StatusInternalServerError )
388
+ render .JSON (w , r , newError (err .Error ()))
389
+ return
390
+ }
408
391
392
+ onSuccess ()
409
393
render .NoContent (w , r )
410
394
}
0 commit comments