MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / DBStart

Method DBStart

tools/mage/dev.go:176–227  ·  view source on GitHub ↗

DBStart starts the databases of the development environment.

()

Source from the content-addressed store, hash-verified

174
175// DBStart starts the databases of the development environment.
176func (Dev) DBStart() error {
177 if mg.Verbose() {
178 fmt.Println("Starting dev databases")
179 }
180 if err := execDockerCompose(append([]string{"up", "-d"}, devDatabases...)...); err != nil {
181 return err
182 }
183
184 // When TimescaleDB starts for the first time, it restarts Postgres after initialization.
185 // Therefore, pg_isready may return a successful exit code during initialization, while the database shuts down
186 // shortly after. Therefore, the ready check goes in two cycles and only returns after 10 successive ready
187 // indications.
188 if mg.Verbose() {
189 fmt.Println("Waiting for Postgres to be ready")
190 }
191 flags := dockerComposeFlags("exec", "-T", "postgres", "pg_isready")
192nextCycle:
193 for i := 0; i < 2; i++ {
194 var (
195 wasReady bool
196 successiveReady int
197 )
198 for j := 0; j < 30; j++ {
199 time.Sleep(time.Second)
200 _, err := sh.Exec(nil, nil, nil, "docker", flags...)
201 isReady := err == nil
202 switch {
203 case wasReady && !isReady:
204 if mg.Verbose() {
205 fmt.Println("Postgres is not ready anymore")
206 }
207 continue nextCycle
208 case !wasReady && isReady:
209 if mg.Verbose() {
210 fmt.Println("Postgres is ready, checking if it stays ready")
211 }
212 successiveReady = 1
213 case wasReady && isReady:
214 successiveReady++
215 if successiveReady == 10 {
216 if mg.Verbose() {
217 fmt.Println("Postgres ready state seems stable")
218 }
219 return nil
220 }
221 }
222 wasReady = isReady
223 }
224 return errors.New("No ready indication within 30 checks")
225 }
226 return errors.New("Postgres is not ready")
227}
228
229// DBStop stops the databases of the development environment.
230func (Dev) DBStop() error {

Callers

nothing calls this directly

Calls 3

execDockerComposeFunction · 0.85
dockerComposeFlagsFunction · 0.85
NewMethod · 0.65

Tested by

no test coverage detected