// writePoolInstances will write (and override) a single cluster name mapping func writePoolInstances(pool string, instanceKeys [](*InstanceKey)) error { writeFunc := func() error { db, err := db.OpenOrchestrator() if err != nil { return log.Errore(err) } tx, err := db.Begin() stmt, err := tx.Prepare(`delete from database_instance_pool where pool = ?`) _, err = stmt.Exec(pool) if err != nil { tx.Rollback() return log.Errore(err) } stmt, err = tx.Prepare(`insert into database_instance_pool (hostname, port, pool, registered_at) values (?, ?, ?, now())`) for _, instanceKey := range instanceKeys { _, err := stmt.Exec(instanceKey.Hostname, instanceKey.Port, pool) if err != nil { tx.Rollback() return log.Errore(err) } } if err != nil { tx.Rollback() return log.Errore(err) } tx.Commit() return nil } return ExecDBWriteFunc(writeFunc) }
// Just check to make sure we can connect to the database func SimpleHealthTest() (*HealthStatus, error) { health := HealthStatus{Healthy: false, Hostname: ThisHostname, Token: ProcessToken.Hash} db, err := db.OpenOrchestrator() if err != nil { health.Error = err return &health, log.Errore(err) } if err = db.Ping(); err != nil { health.Error = err return &health, log.Errore(err) } else { health.Healthy = true return &health, nil } }