77 "time"
88
99 "github.com/gin-gonic/gin"
10+ dbresolver "github.com/sivaosorg/db.resolver"
1011 syncconf "github.com/sivaosorg/gocell/internal/syncConf"
1112 "github.com/sivaosorg/gocell/pkg/constant"
1213 "github.com/sivaosorg/govm/blueprint"
@@ -32,6 +33,7 @@ type CoreCommand struct {
3233 handlers * coreHandler
3334 rabbitmq * rabbitmqconn.RabbitMq
3435 rabbitmqStatus dbx.Dbx
36+ resolver * dbresolver.MultiTenantDBResolver
3537}
3638
3739func (c * CoreCommand ) Name () string {
@@ -50,6 +52,7 @@ func (c *CoreCommand) Execute(args []string) error {
5052 if err != nil {
5153 return err
5254 }
55+ c .seeker ()
5356 c .conn ()
5457 c .notify ()
5558 c .handler ()
@@ -61,11 +64,6 @@ func (c *CoreCommand) conn() {
6164 if syncconf .Conf == nil {
6265 return
6366 }
64- syncconf .Conf .Postgres .SetTimeout (10 * time .Second )
65- syncconf .Conf .MySql .SetTimeout (10 * time .Second )
66- syncconf .Conf .Redis .SetTimeout (10 * time .Second )
67- syncconf .Conf .RabbitMq .SetTimeout (10 * time .Second )
68-
6967 // Instances async
7068 var wg sync.WaitGroup
7169 wg .Add (1 )
@@ -96,9 +94,34 @@ func (c *CoreCommand) conn() {
9694 c .rabbitmq = rabbitmq
9795 c .rabbitmqStatus = s
9896 }()
97+ wg .Add (1 )
98+ go func () {
99+ defer wg .Done ()
100+ c .resolver .
101+ AddPsqlConnectors (syncconf .Conf .PostgresSeekers ... ).
102+ AddMsqlConnectors (syncconf .Conf .MySqlSeekers ... ).
103+ SetDefaultConnector (dbresolver .NewPostgresConnector (syncconf .Conf .Postgres ))
104+ }()
99105 wg .Wait ()
100106}
101107
108+ func (c * CoreCommand ) seeker () {
109+ c .resolver = dbresolver .NewMultiTenantDBResolver ()
110+ timeout := 10 * time .Second
111+ syncconf .Conf .Postgres .SetTimeout (timeout )
112+ syncconf .Conf .MySql .SetTimeout (timeout )
113+ syncconf .Conf .Redis .SetTimeout (timeout )
114+ syncconf .Conf .RabbitMq .SetTimeout (timeout )
115+
116+ // updating timeout for context db ping
117+ for idx := range syncconf .Conf .PostgresSeekers {
118+ syncconf .Conf .PostgresSeekers [idx ].Config .SetTimeout (timeout )
119+ }
120+ for idx := range syncconf .Conf .MySqlSeekers {
121+ syncconf .Conf .MySqlSeekers [idx ].Config .SetTimeout (timeout )
122+ }
123+ }
124+
102125func (c * CoreCommand ) run () {
103126 gin .SetMode (syncconf .Conf .Server .Mode )
104127 core := gin .New ()
0 commit comments