refactor main_rotation_cycle to streamline node processing and container management
This commit is contained in:
@ -281,17 +281,13 @@ def main_rotation_cycle():
|
||||
|
||||
logger.info("Starting nexus rotation cycle")
|
||||
|
||||
while True:
|
||||
cycle_count += 1
|
||||
logger.info(f"=== Starting cycle #{cycle_count} ===")
|
||||
|
||||
try:
|
||||
# Get next node
|
||||
node = get_next_node(grist, logger)
|
||||
if not node:
|
||||
logger.error("No node available, waiting 60 seconds before retry")
|
||||
time.sleep(60)
|
||||
continue
|
||||
return
|
||||
|
||||
node_id = node.NodeID
|
||||
current_hours = int(node.Hours)
|
||||
@ -311,7 +307,7 @@ def main_rotation_cycle():
|
||||
grist.update(node.id, {"Hours": current_hours}, "Nodes")
|
||||
logger.info(f"Reverted node {node_id} hours back to: {current_hours}")
|
||||
time.sleep(60)
|
||||
continue
|
||||
return
|
||||
|
||||
logger.info(f"Container started successfully for node {node_id}")
|
||||
|
||||
@ -348,7 +344,7 @@ def main_rotation_cycle():
|
||||
# If container failed during the cycle, skip to next iteration
|
||||
if container_failed:
|
||||
logger.error(f"Container failed during cycle for node {node_id}, moving to next node")
|
||||
continue
|
||||
return
|
||||
|
||||
# Stop and remove container
|
||||
logger.info(f"5 hours completed for node {node_id}, stopping container")
|
||||
@ -361,17 +357,7 @@ def main_rotation_cycle():
|
||||
|
||||
logger.info(f"=== Cycle #{cycle_count} completed for node {node_id} ===")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
logger.info("Received keyboard interrupt, stopping rotation")
|
||||
stop_and_remove_container(container_name, logger)
|
||||
break
|
||||
except Exception as e:
|
||||
logger.error(f"Cycle #{cycle_count} failed with error: {str(e)}")
|
||||
stop_and_remove_container(container_name, logger)
|
||||
logger.info("Waiting 60 seconds before next attempt")
|
||||
time.sleep(60)
|
||||
|
||||
logger.info("Nexus rotation cycle stopped")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user