Ejemplo n.º 1
0
// Reconnect function, attempts to reconnect once per second
func reconnect(db *mysql.MySQL, done chan int) {
	attempts := 0
	for {
		// Sleep for 1 second
		time.Sleep(1000000000)
		// Attempt to reconnect
		db.Reconnect()
		// If there was no error break for loop
		if db.Errno == 0 {
			break
		} else {
			attempts++
			fmt.Printf("Reconnect attempt %d failed\n", attempts)
		}
	}
	done <- 1
}
Ejemplo n.º 2
0
// Reconnect function, attempts to reconnect once per second
func reconnect(db *mysql.MySQL, done chan bool) {
	var err os.Error
	attempts := 0

	for {
		// Sleep for 1 second
		time.Sleep(1e9)

		// Attempt to reconnect
		if err = db.Reconnect(); err != nil {
			break
		}

		attempts++
		fmt.Fprintf(os.Stderr, "Reconnect attempt %d failed\n", attempts)
	}

	done <- true
}