modify alert sql

This commit is contained in:
menshibin 2024-08-12 22:55:35 +08:00
parent 9ae084ee6e
commit b9165de6b2
2 changed files with 16 additions and 14 deletions

View File

@ -142,17 +142,17 @@ def seek_offset(consumer):
raise err raise err
# ANCHOR_END: assignment # ANCHOR_END: assignment
# ANCHOR: unsubscribe
def unsubscribe(consumer): def unsubscribe(consumer):
# ANCHOR: unsubscribe
try: try:
consumer.unsubscribe() consumer.unsubscribe()
print("Consumer unsubscribed successfully."); print("Consumer unsubscribed successfully.");
except Exception as err: except Exception as err:
print(f"Failed to unsubscribe consumer. ErrMessage:{err}") print(f"Failed to unsubscribe consumer. ErrMessage:{err}")
finally:
if consumer:
# ANCHOR_END: unsubscribe consumer.close()
# ANCHOR_END: unsubscribe
if __name__ == "__main__": if __name__ == "__main__":
consumer = None consumer = None
@ -162,9 +162,10 @@ if __name__ == "__main__":
subscribe(consumer) subscribe(consumer)
seek_offset(consumer) seek_offset(consumer)
commit_offset(consumer) commit_offset(consumer)
unsubscribe(consumer) consumer.unsubscribe()
print("Consumer unsubscribed successfully.");
except Exception as err: except Exception as err:
print(f"Failed to stmt consumer. ErrMessage:{err}") print(f"Failed to stmt consumer. ErrMessage:{err}")
finally: finally:
if consumer: consumer.unsubscribe()
consumer.close()

View File

@ -143,14 +143,17 @@ def commit_offset(consumer):
# ANCHOR_END: commit_offset # ANCHOR_END: commit_offset
# #
# ANCHOR: unsubscribe
def unsubscribe(consumer): def unsubscribe(consumer):
# ANCHOR: unsubscribe
try: try:
consumer.unsubscribe() consumer.unsubscribe()
print("Consumer unsubscribed successfully."); print("Consumer unsubscribed successfully.");
except Exception as err: except Exception as err:
print(f"Failed to unsubscribe consumer. ErrMessage:{err}") print(f"Failed to unsubscribe consumer. ErrMessage:{err}")
finally:
if consumer:
consumer.close()
# ANCHOR_END: unsubscribe # ANCHOR_END: unsubscribe
@ -162,9 +165,7 @@ if __name__ == "__main__":
subscribe(consumer) subscribe(consumer)
seek_offset(consumer) seek_offset(consumer)
commit_offset(consumer) commit_offset(consumer)
unsubscribe(consumer)
except Exception as err: except Exception as err:
print(f"Failed to stmt consumer. ErrorMessage:{err}") print(f"Failed to stmt consumer. ErrorMessage:{err}")
finally: finally:
if consumer: unsubscribe(consumer);
consumer.close()