Refactor the Periodic Scanner module (#1210)

* Initial fix of a race condition

* better logging

* some refactoring and graceful shutdown

* fix more potential race condition places; a better app shutdown

* add test and fix some issues

* some housekeeping

* more descriptive asserts

* Address review suggestions

* Better server shutdown logic + better message about the .env file not found

* Create context inside the shutdown goroutine; removed unnecessary shutdown from the main function

* Move HTTP server to the main process and remove unnecessary code

* log shutdown error if any

* Get back to the local `scanner` variable

* Protecting scanner with mutex

* Adding the mutex to the shutdown function

* Addressing the race condition at the init stage

---------

Co-authored-by: Konstantin Koval
This commit is contained in:
Kostiantyn
2025-06-11 17:09:22 +03:00
committed by GitHub
parent 0da8bef69e
commit a22967b7d0
5 changed files with 428 additions and 29 deletions

View File

@@ -86,6 +86,8 @@ github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NF
github.com/sosodev/duration v1.3.1 h1:qtHBDMQ6lvMQsL15g4aopM4HEfOaYuhWBw3NPTtlqq4=
github.com/sosodev/duration v1.3.1/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=