modify alert sql
This commit is contained in:
parent
d72e0307f0
commit
ffebe1d4c9
|
@ -25,8 +25,10 @@ async function createDbAndTable() {
|
||||||
let wsSql = null;
|
let wsSql = null;
|
||||||
try {
|
try {
|
||||||
wsSql = await createConnect();
|
wsSql = await createConnect();
|
||||||
|
// create database
|
||||||
await wsSql.exec('CREATE DATABASE IF NOT EXISTS power');
|
await wsSql.exec('CREATE DATABASE IF NOT EXISTS power');
|
||||||
|
console.log("Create database power successfully.");
|
||||||
|
// create table
|
||||||
await wsSql.exec('CREATE STABLE IF NOT EXISTS power.meters ' +
|
await wsSql.exec('CREATE STABLE IF NOT EXISTS power.meters ' +
|
||||||
'(_ts timestamp, current float, voltage int, phase float) ' +
|
'(_ts timestamp, current float, voltage int, phase float) ' +
|
||||||
'TAGS (location binary(64), groupId int);');
|
'TAGS (location binary(64), groupId int);');
|
||||||
|
@ -109,7 +111,7 @@ async function sqlWithReqid() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error("Failed to execute sql with reqId: " + reqId + "," + err.code + "; ErrMessage: " + err.message);
|
console.error("Failed to execute sql with reqId: " + reqId + ", ErrCode:" + err.code + "; ErrMessage: " + err.message);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (wsRows) {
|
if (wsRows) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ def create_connection():
|
||||||
)
|
)
|
||||||
print(f"Connected to {host}:{port} successfully.");
|
print(f"Connected to {host}:{port} successfully.");
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to connect to {host}:{port} ; err:{err}")
|
print(f"Failed to connect to {host}:{port} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -12,7 +12,7 @@ def create_connection():
|
||||||
|
|
||||||
print(f"Connected to {url} successfully.");
|
print(f"Connected to {url} successfully.");
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to connect to {url} ; err:{err}")
|
print(f"Failed to connect to {url} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -14,7 +14,7 @@ def create_connection():
|
||||||
)
|
)
|
||||||
print(f"Connected to {host}:{port} successfully.");
|
print(f"Connected to {host}:{port} successfully.");
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to connect to {host}:{port} ; Err:{err}")
|
print(f"Failed to connect to {host}:{port} ; ErrMessage:{err}")
|
||||||
|
|
||||||
return conn
|
return conn
|
||||||
# ANCHOR_END: connect
|
# ANCHOR_END: connect
|
||||||
|
|
|
@ -20,7 +20,7 @@ try:
|
||||||
print(f"Create stable power.meters successfully, rowsAffected: {rowsAffected}");
|
print(f"Create stable power.meters successfully, rowsAffected: {rowsAffected}");
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to create db and table, db addr:{host}:{port} ; err:{err}")
|
print(f"Failed to create db and table, db addr:{host}:{port} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -19,7 +19,7 @@ try:
|
||||||
print(f"Create stable power.meters successfully, rowsAffected: {rowsAffected}");
|
print(f"Create stable power.meters successfully, rowsAffected: {rowsAffected}");
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to create db and table, url:{url} ; err:{err}")
|
print(f"Failed to create db and table, url:{url} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -20,7 +20,7 @@ try:
|
||||||
print(f"Create stable power.meters successfully, rowsAffected: {rowsAffected}");
|
print(f"Create stable power.meters successfully, rowsAffected: {rowsAffected}");
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to create db and table, db addrr:{host}:{port} ; err:{err}")
|
print(f"Failed to create db and table, db addrr:{host}:{port} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -21,7 +21,7 @@ try:
|
||||||
print(f"Successfully inserted {affectedRows} rows to power.meters.")
|
print(f"Successfully inserted {affectedRows} rows to power.meters.")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to insert data to power.meters, db addr:{host}:{port} ; err:{err}")
|
print(f"Failed to insert data to power.meters, db addr:{host}:{port} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -20,7 +20,7 @@ try:
|
||||||
print(f"Successfully inserted {affectedRows} rows to power.meters.")
|
print(f"Successfully inserted {affectedRows} rows to power.meters.")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to insert data to power.meters, url:{url} ; err:{err}")
|
print(f"Failed to insert data to power.meters, url:{url} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -21,7 +21,7 @@ try:
|
||||||
print(f"Successfully inserted {affectedRows} rows to power.meters.")
|
print(f"Successfully inserted {affectedRows} rows to power.meters.")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to insert data to power.meters, db addr:{host}:{port} ; err:{err}")
|
print(f"Failed to insert data to power.meters, db addr:{host}:{port} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -15,7 +15,7 @@ try:
|
||||||
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to query data from power.meters, db addr:{host}:{port} ; err:{err}")
|
print(f"Failed to query data from power.meters, db addr:{host}:{port} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
|
@ -14,4 +14,4 @@ try:
|
||||||
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to query data from power.meters, url:{url} ; err:{err}")
|
print(f"Failed to query data from power.meters, url:{url} ; ErrMessage:{err}")
|
||||||
|
|
|
@ -14,7 +14,7 @@ try:
|
||||||
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to query data from power.meters, db addr:{host}:{port} ; err:{err}")
|
print(f"Failed to query data from power.meters, db addr:{host}:{port} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -17,7 +17,7 @@ try:
|
||||||
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to execute sql with reqId:{reqId}, db addr:{host}:{port} ; err:{err}")
|
print(f"Failed to execute sql with reqId:{reqId}, db addr:{host}:{port} ; ErrMessage:{err}")
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
|
|
|
@ -15,4 +15,4 @@ try:
|
||||||
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to execute sql with reqId:{reqId}, url:{url} ; err:{err}")
|
print(f"Failed to execute sql with reqId:{reqId}, url:{url} ; ErrMessage:{err}")
|
||||||
|
|
|
@ -18,7 +18,7 @@ try:
|
||||||
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to execute sql with reqId:{reqId}, db addr:{host}:{port} ; err:{err}")
|
print(f"Failed to execute sql with reqId:{reqId}, db addr:{host}:{port} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
|
@ -34,7 +34,7 @@ try:
|
||||||
)
|
)
|
||||||
print("Inserted data with schemaless successfully.");
|
print("Inserted data with schemaless successfully.");
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to insert data with schemaless, addr: {host}:{port} err:{err}")
|
print(f"Failed to insert data with schemaless, addr: {host}:{port} ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -66,7 +66,7 @@ def schemaless_insert():
|
||||||
)
|
)
|
||||||
print("Inserted data with schemaless successfully.");
|
print("Inserted data with schemaless successfully.");
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to insert data with schemaless, addr: {host}:{port} err:{err}")
|
print(f"Failed to insert data with schemaless, addr: {host}:{port} ErrMessage:{err}")
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -56,7 +56,7 @@ try:
|
||||||
print(f"Successfully inserted to power.meters.")
|
print(f"Successfully inserted to power.meters.")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to insert to table meters using stmt, addr:{host}:{port} ; err:{err}")
|
print(f"Failed to insert to table meters using stmt, addr:{host}:{port} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if stmt:
|
if stmt:
|
||||||
stmt.close()
|
stmt.close()
|
||||||
|
|
|
@ -61,7 +61,7 @@ try:
|
||||||
print(f"Successfully inserted to power.meters.")
|
print(f"Successfully inserted to power.meters.")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to insert to table meters using stmt, addr:{host}:{port} ; err:{err}")
|
print(f"Failed to insert to table meters using stmt, addr:{host}:{port} ; ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if stmt:
|
if stmt:
|
||||||
stmt.close()
|
stmt.close()
|
||||||
|
|
|
@ -39,7 +39,7 @@ def prepareMeta():
|
||||||
affectedRows = conn.execute(sql)
|
affectedRows = conn.execute(sql)
|
||||||
print(f"inserted into {affectedRows} rows to power.meters successfully.")
|
print(f"inserted into {affectedRows} rows to power.meters successfully.")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"prepare meta err:{err}")
|
print(f"prepare meta ErrMessage:{err}")
|
||||||
raise err
|
raise err
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
|
@ -70,7 +70,7 @@ def create_consumer():
|
||||||
print(f"Create consumer successfully, host: {host}:{port}, groupId: {groupId}, clientId: {clientId}");
|
print(f"Create consumer successfully, host: {host}:{port}, groupId: {groupId}, clientId: {clientId}");
|
||||||
return consumer
|
return consumer
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to create websocket consumer, host: {host}:{port} ; err:{err}");
|
print(f"Failed to create websocket consumer, host: {host}:{port} ; ErrMessage:{err}");
|
||||||
raise err
|
raise err
|
||||||
# ANCHOR_END: create_consumer
|
# ANCHOR_END: create_consumer
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ def subscribe(consumer):
|
||||||
print(f"data: {data}")
|
print(f"data: {data}")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to poll data, err:{err}")
|
print(f"Failed to poll data, ErrMessage:{err}")
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ def commit_offset(consumer):
|
||||||
print("commit offset manually successfully.");
|
print("commit offset manually successfully.");
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to poll data, err:{err}")
|
print(f"Failed to poll data, ErrMessage:{err}")
|
||||||
raise err
|
raise err
|
||||||
# ANCHOR_END: commit_offset
|
# ANCHOR_END: commit_offset
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ def seek_offset(consumer):
|
||||||
consumer.seek(partition)
|
consumer.seek(partition)
|
||||||
print(f"assignment seek to beginning successfully");
|
print(f"assignment seek to beginning successfully");
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"seek example failed; err:{err}")
|
print(f"seek example failed; ErrMessage:{err}")
|
||||||
raise err
|
raise err
|
||||||
# ANCHOR_END: assignment
|
# ANCHOR_END: assignment
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ def unsubscribe(consumer):
|
||||||
consumer.unsubscribe()
|
consumer.unsubscribe()
|
||||||
print("unsubscribe consumer successfully.");
|
print("unsubscribe consumer successfully.");
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to unsubscribe consumer. err:{err}")
|
print(f"Failed to unsubscribe consumer. ErrMessage:{err}")
|
||||||
|
|
||||||
|
|
||||||
# ANCHOR_END: unsubscribe
|
# ANCHOR_END: unsubscribe
|
||||||
|
@ -165,7 +165,7 @@ if __name__ == "__main__":
|
||||||
commit_offset(consumer)
|
commit_offset(consumer)
|
||||||
unsubscribe(consumer)
|
unsubscribe(consumer)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to stmt consumer. err:{err}")
|
print(f"Failed to stmt consumer. ErrMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if consumer:
|
if consumer:
|
||||||
consumer.close()
|
consumer.close()
|
|
@ -51,7 +51,7 @@ def prepareMeta():
|
||||||
print(f"inserted into {affectedRows} rows to power.meters successfully.")
|
print(f"inserted into {affectedRows} rows to power.meters successfully.")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to prepareMeta {err}")
|
print(f"Failed to prepareMeta ErrMessage:{err}")
|
||||||
raise err
|
raise err
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
|
@ -78,7 +78,7 @@ def create_consumer():
|
||||||
print(f"Create consumer successfully, host: {host}:{port}, groupId: {groupId}, clientId: {clientId}");
|
print(f"Create consumer successfully, host: {host}:{port}, groupId: {groupId}, clientId: {clientId}");
|
||||||
return consumer;
|
return consumer;
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to create websocket consumer, host: {host}:{port} ; err:{err}");
|
print(f"Failed to create websocket consumer, host: {host}:{port} ; ErrMessage:{err}");
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ def seek_offset(consumer):
|
||||||
print("assignment seek to beginning successfully");
|
print("assignment seek to beginning successfully");
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"seek example failed; err:{err}")
|
print(f"seek example failed; ErrMessage:{err}")
|
||||||
raise err
|
raise err
|
||||||
# ANCHOR_END: assignment
|
# ANCHOR_END: assignment
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ def subscribe(consumer):
|
||||||
print(f"data: {row}")
|
print(f"data: {row}")
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to poll data, err:{err}")
|
print(f"Failed to poll data, ErrMessage:{err}")
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ def commit_offset(consumer):
|
||||||
print("commit offset manually successfully.");
|
print("commit offset manually successfully.");
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to poll data, err:{err}")
|
print(f"Failed to poll data, ErrMessage:{err}")
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
|
|
||||||
|
@ -147,9 +147,9 @@ def commit_offset(consumer):
|
||||||
def unsubscribe(consumer):
|
def unsubscribe(consumer):
|
||||||
try:
|
try:
|
||||||
consumer.unsubscribe()
|
consumer.unsubscribe()
|
||||||
print("unsubscribe consumer successfully.");
|
print("consumer unsubscribed successfully.");
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print("Failed to unsubscribe consumer. err:{err}")
|
print(f"Failed to unsubscribe consumer. ErrMessage:{err}")
|
||||||
|
|
||||||
|
|
||||||
# ANCHOR_END: unsubscribe
|
# ANCHOR_END: unsubscribe
|
||||||
|
@ -164,7 +164,7 @@ if __name__ == "__main__":
|
||||||
commit_offset(consumer)
|
commit_offset(consumer)
|
||||||
unsubscribe(consumer)
|
unsubscribe(consumer)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
print(f"Failed to stmt consumer. err:{err}")
|
print(f"Failed to stmt consumer. ErrorMessage:{err}")
|
||||||
finally:
|
finally:
|
||||||
if consumer:
|
if consumer:
|
||||||
consumer.close()
|
consumer.close()
|
Loading…
Reference in New Issue