mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-02 22:51:34 -06:00
extract pull logic to own manager. (#54)
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"os/signal"
|
||||
"runtime"
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"github.com/m1k1o/neko-rooms/internal/api"
|
||||
"github.com/m1k1o/neko-rooms/internal/config"
|
||||
"github.com/m1k1o/neko-rooms/internal/http"
|
||||
"github.com/m1k1o/neko-rooms/internal/pull"
|
||||
"github.com/m1k1o/neko-rooms/internal/room"
|
||||
)
|
||||
|
||||
@@ -108,6 +110,7 @@ type MainCtx struct {
|
||||
|
||||
logger zerolog.Logger
|
||||
roomManager *room.RoomManagerCtx
|
||||
pullManager *pull.PullManagerCtx
|
||||
apiManager *api.ApiManagerCtx
|
||||
httpManager *http.HttpManagerCtx
|
||||
}
|
||||
@@ -117,12 +120,26 @@ func (main *MainCtx) Preflight() {
|
||||
}
|
||||
|
||||
func (main *MainCtx) Start() {
|
||||
client, err := client.NewClientWithOpts(client.FromEnv)
|
||||
if err != nil {
|
||||
main.logger.Panic().Err(err).Msg("unable to connect to docker client")
|
||||
} else {
|
||||
main.logger.Info().Msg("successfully connected to docker client")
|
||||
}
|
||||
|
||||
main.roomManager = room.New(
|
||||
client,
|
||||
main.Configs.Room,
|
||||
)
|
||||
|
||||
main.pullManager = pull.New(
|
||||
client,
|
||||
main.Configs.Room.NekoImages,
|
||||
)
|
||||
|
||||
main.apiManager = api.New(
|
||||
main.roomManager,
|
||||
main.pullManager,
|
||||
main.Configs.API,
|
||||
)
|
||||
|
||||
@@ -135,11 +152,8 @@ func (main *MainCtx) Start() {
|
||||
}
|
||||
|
||||
func (main *MainCtx) Shutdown() {
|
||||
if err := main.httpManager.Shutdown(); err != nil {
|
||||
main.logger.Err(err).Msg("http manager shutdown with an error")
|
||||
} else {
|
||||
main.logger.Debug().Msg("http manager shutdown")
|
||||
}
|
||||
err := main.httpManager.Shutdown()
|
||||
main.logger.Err(err).Msg("http manager shutdown")
|
||||
}
|
||||
|
||||
func (main *MainCtx) ServeCommand(cmd *cobra.Command, args []string) {
|
||||
@@ -151,7 +165,7 @@ func (main *MainCtx) ServeCommand(cmd *cobra.Command, args []string) {
|
||||
signal.Notify(quit, os.Interrupt)
|
||||
sig := <-quit
|
||||
|
||||
main.logger.Warn().Msgf("received %s, attempting graceful shutdown: \n", sig)
|
||||
main.logger.Warn().Msgf("received %s, attempting graceful shutdown.", sig)
|
||||
main.Shutdown()
|
||||
main.logger.Info().Msg("shutdown complete")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user