Add format_number function to checker.py for improved subscription ID formatting
This update introduces a new `format_number` function that formats subscription IDs into a more readable format (e.g., converting 1000 to '1k'). The `check_logs` function has been modified to utilize this new formatting for both head subscription ID and last subscription ID in the status messages, enhancing clarity in log analysis and improving the overall readability of subscription status reporting.
This commit is contained in:
parent
382a910856
commit
57c8b81c13
10
checker.py
10
checker.py
@ -134,6 +134,12 @@ def clean_ansi(text):
|
|||||||
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
|
||||||
return ansi_escape.sub('', text)
|
return ansi_escape.sub('', text)
|
||||||
|
|
||||||
|
def format_number(number_str):
|
||||||
|
number = int(number_str)
|
||||||
|
if number >= 1000:
|
||||||
|
return f"{number//1000}k"
|
||||||
|
return str(number)
|
||||||
|
|
||||||
def check_logs(logger):
|
def check_logs(logger):
|
||||||
try:
|
try:
|
||||||
logs = subprocess.run(['docker', 'logs', '--since', '10m', 'infernet-node'], capture_output=True, text=True, check=True)
|
logs = subprocess.run(['docker', 'logs', '--since', '10m', 'infernet-node'], capture_output=True, text=True, check=True)
|
||||||
@ -155,11 +161,11 @@ def check_logs(logger):
|
|||||||
|
|
||||||
if head_sub_id:
|
if head_sub_id:
|
||||||
logger.info(f"Head sub id: {head_sub_id}")
|
logger.info(f"Head sub id: {head_sub_id}")
|
||||||
return {"status": f"OK: {head_sub_id}"}
|
return {"status": f"OK: {format_number(head_sub_id)}"}
|
||||||
|
|
||||||
if last_subscription_id:
|
if last_subscription_id:
|
||||||
logger.info(f"Subscription: {last_subscription_id}")
|
logger.info(f"Subscription: {last_subscription_id}")
|
||||||
return {"status": f"Sync: {last_subscription_id}"}
|
return {"status": f"Sync: {format_number(last_subscription_id)}"}
|
||||||
|
|
||||||
logger.info("Not found subscription")
|
logger.info("Not found subscription")
|
||||||
return {"status": "Idle"}
|
return {"status": "Idle"}
|
||||||
|
Loading…
Reference in New Issue
Block a user