|
|
|
@ -6,12 +6,12 @@ package service
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"github.com/rocboss/paopao-ce/internal/conf"
|
|
|
|
|
"github.com/rocboss/paopao-ce/pkg/util"
|
|
|
|
|
"github.com/sourcegraph/conc"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
@ -50,21 +50,19 @@ func (p *serverPool[T]) from(addr string, newServer func() T) T {
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *serverPool[T]) startServer(wg *sync.WaitGroup, maxSidSize int) {
|
|
|
|
|
func (p *serverPool[T]) startServer(wg *conc.WaitGroup, maxSidSize int) {
|
|
|
|
|
for _, srv := range p.servers {
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
go func(t T) {
|
|
|
|
|
ss := t.services()
|
|
|
|
|
if len(ss) < 1 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
ss := srv.services()
|
|
|
|
|
if len(ss) == 0 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
startSrv := srv.start
|
|
|
|
|
wg.Go(func() {
|
|
|
|
|
for _, s := range ss {
|
|
|
|
|
colorPrint(actOnStart, s.OnStart(), maxSidSize, s)
|
|
|
|
|
}
|
|
|
|
|
colorPrint(actStart, t.start(), maxSidSize, ss...)
|
|
|
|
|
// remember to done sync.WaitGroup
|
|
|
|
|
wg.Done()
|
|
|
|
|
}(srv)
|
|
|
|
|
colorPrint(actStart, startSrv(), maxSidSize, ss...)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -164,7 +162,7 @@ func colorPrint(act byte, err error, l int, ss ...Service) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start start all servers
|
|
|
|
|
func Start(wg *sync.WaitGroup) {
|
|
|
|
|
func Start(wg *conc.WaitGroup) {
|
|
|
|
|
srvSize, maxSidSize := checkServices()
|
|
|
|
|
if srvSize < 1 {
|
|
|
|
|
return
|
|
|
|
|