Wait for server shutdown when stopping server

This commit is contained in:
Pijus Kamandulis 2025-02-03 22:21:54 +02:00
parent 3fee3bc816
commit da1566875b
4 changed files with 29 additions and 6 deletions

View File

@ -7,18 +7,21 @@ import (
) )
type ApiServer struct { type ApiServer struct {
stopServer chan interface{} stopServer chan interface{}
isActive bool onServerShutdown chan interface{}
router *gin.Engine isActive bool
config config.ServerConfig router *gin.Engine
config config.ServerConfig
} }
func NewApiServer(dataRepository *repositories.DataRepository, config config.ServerConfig) *ApiServer { func NewApiServer(dataRepository *repositories.DataRepository, config config.ServerConfig) *ApiServer {
stopChan := make(chan interface{}) stopChan := make(chan interface{})
onServerShutdownChan := make(chan interface{})
apiServer := &ApiServer{ apiServer := &ApiServer{
stopServer: stopChan, stopServer: stopChan,
config: config, onServerShutdown: onServerShutdownChan,
config: config,
} }
apiServer.CreateRouter(dataRepository) apiServer.CreateRouter(dataRepository)
@ -32,4 +35,5 @@ func (s *ApiServer) GetRouter() *gin.Engine {
func (s *ApiServer) Stop() { func (s *ApiServer) Stop() {
s.stopServer <- true s.stopServer <- true
<-s.onServerShutdown
} }

View File

@ -102,6 +102,7 @@ func (s *ApiServer) Start() {
if err != nil { if err != nil {
logger.ErrorLn("Failed to shutdown server:", err) logger.ErrorLn("Failed to shutdown server:", err)
} }
s.onServerShutdown <- true
}() }()
go func() { go func() {

View File

@ -204,6 +204,15 @@ Cosmium strives to support the core features of Cosmos DB, including:
| IS_PRIMITIVE | Yes | | IS_PRIMITIVE | Yes |
| IS_STRING | Yes | | IS_STRING | Yes |
### Document Batch Requests
| Operation | Implemented |
| --------- | ----------- |
| Create | No |
| Update | No |
| Delete | No |
| Read | No |
## Known Differences ## Known Differences
While Cosmium aims to replicate the behavior of Cosmos DB as closely as possible, there are certain differences and limitations to be aware of: While Cosmium aims to replicate the behavior of Cosmos DB as closely as possible, there are certain differences and limitations to be aware of:

View File

@ -1,8 +1,12 @@
package main package main
/*
#include <stdlib.h>
*/
import "C" import "C"
import ( import (
"encoding/json" "encoding/json"
"unsafe"
"github.com/pikami/cosmium/api" "github.com/pikami/cosmium/api"
"github.com/pikami/cosmium/api/config" "github.com/pikami/cosmium/api/config"
@ -87,4 +91,9 @@ func LoadServerInstanceState(serverName *C.char, stateJSON *C.char) int {
return ResponseServerInstanceNotFound return ResponseServerInstanceNotFound
} }
//export FreeMemory
func FreeMemory(ptr *C.char) {
C.free(unsafe.Pointer(ptr))
}
func main() {} func main() {}