示例#1
0
func (my *MySQLNodeDB) Insert() bool {
	defer my.db.Close()
	tx := my.db.MustBegin()
	tx.MustExec("INSERT INTO "+table+" (hostname, host_ips, connected_on, last_update) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE hostname=?, host_ips=?, connected_on=?, last_update=?",
		utils.GetSystemHostname(),
		utils.GetLocalIp(),
		time.Now().UTC(),
		time.Now().UTC(),
		utils.GetSystemHostname(),
		utils.GetLocalIp(),
		time.Now().UTC(),
		time.Now().UTC())
	err := tx.Commit()
	if err != nil {
		log.Criticalf("Error setting node alive: %s", err.Error())
	}
	return true
}
示例#2
0
func (my *MySQLNodeDB) Update() bool {
	defer my.db.Close()
	tx := my.db.MustBegin()
	tx.MustExec("UPDATE "+table+" SET hostname=?, host_ips=?, last_update=? where hostname=?",
		utils.GetSystemHostname(),
		utils.GetLocalIp(),
		time.Now().UTC(),
		utils.GetSystemHostname())
	err := tx.Commit()
	if err != nil {
		log.Errorf("Error updating node alive status: %s", err.Error())
	}
	return true
}