60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
configcore "bitrix_balancer_api/core/config"
|
|
clientcontrollers "bitrix_balancer_api/core/lib/internally/client-controllers"
|
|
workerjobs "bitrix_balancer_api/system_service/jobs"
|
|
"bitrix_balancer_api/system_service/types"
|
|
"errors"
|
|
"fmt"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func main() {
|
|
err := initService()
|
|
if err != nil {
|
|
logrus.Error(errors.New(fmt.Sprintf("failed to init service: %v", err)))
|
|
return
|
|
}
|
|
select {}
|
|
}
|
|
|
|
func initService() error {
|
|
clientsExternal, err := getClientsExternal()
|
|
if err != nil {
|
|
return errors.New(fmt.Sprintf("failed to load config: %v", err))
|
|
}
|
|
|
|
ipc, err := initInternalProvider(clientsExternal)
|
|
if err != nil {
|
|
return errors.New(fmt.Sprintf("🔴 failed to init internal provider: %v", err))
|
|
}
|
|
if ipc == nil {
|
|
return errors.New("failed to init internal provider: nil ipc")
|
|
}
|
|
|
|
// Запуск воркеров
|
|
err = workerjobs.WorkerJobsStart(ipc)
|
|
if err != nil {
|
|
return errors.New(fmt.Sprintf("failed to init workerjobs: %v", err))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func initInternalProvider(clientsExternal clientcontrollers.ClientsExternal) (*types.InternalProviderControl, error) {
|
|
return &types.InternalProviderControl{
|
|
Database: clientsExternal.DB,
|
|
Config: clientsExternal.Config,
|
|
RedisClient: clientsExternal.Redis,
|
|
}, nil
|
|
}
|
|
|
|
func getClientsExternal() (clientcontrollers.ClientsExternal, error) {
|
|
options := &configcore.ConfigLoadOptions{
|
|
Redis: true,
|
|
Database: true,
|
|
}
|
|
return clientcontrollers.ReturnClientsExternal(options)
|
|
}
|