mirror of
https://github.com/blw1138/cross-py-builder.git
synced 2025-12-17 08:38:11 +00:00
Fixed issue with updates after builds and restarting process
This commit is contained in:
@@ -15,6 +15,8 @@ import requests
|
||||
from build_agent import build_agent_version
|
||||
from zeroconf_server import ZeroconfServer
|
||||
|
||||
TIMEOUT = 10
|
||||
|
||||
def find_server_ips():
|
||||
ZeroconfServer.configure("_crosspybuilder._tcp.local.", socket.gethostname(), 9001)
|
||||
hostnames = []
|
||||
@@ -47,12 +49,13 @@ def get_all_servers_status():
|
||||
def get_worker_status(hostname):
|
||||
"""Fetch worker status from the given hostname."""
|
||||
try:
|
||||
response = requests.get(f"http://{hostname}:9001/status", timeout=5)
|
||||
response = requests.get(f"http://{hostname}:9001/status", timeout=TIMEOUT)
|
||||
status = response.json()
|
||||
if status['hostname'] != hostname and status['ip'] != hostname:
|
||||
status['ip'] = socket.gethostbyname(hostname)
|
||||
return status
|
||||
except requests.exceptions.RequestException:
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"EXCEPTION: {e}")
|
||||
return {"hostname": hostname, "status": "offline"}
|
||||
|
||||
|
||||
@@ -71,8 +74,7 @@ def zip_project(source_dir, output_zip):
|
||||
def send_build_request(zip_file, server_ip, download_after=False):
|
||||
"""Uploads the zip file to the given server."""
|
||||
upload_url = f"http://{server_ip}:9001/upload"
|
||||
print(f"Submitting build request to URL: {upload_url}")
|
||||
print("Please wait. This may take a few minutes...")
|
||||
print(f"Submitting build request to URL: {upload_url} - Please wait. This may take a few minutes...")
|
||||
with open(zip_file, 'rb') as f:
|
||||
response = requests.post(upload_url, files={"file": f})
|
||||
|
||||
@@ -189,7 +191,7 @@ def update_worker(server):
|
||||
response_json = response.json()
|
||||
if response_json.get('updated_files') and not response_json.get('error_files'):
|
||||
try:
|
||||
requests.get(f"http://{server['ip']}:9001/restart", timeout=2)
|
||||
requests.get(f"http://{server['ip']}:9001/restart", timeout=TIMEOUT)
|
||||
except requests.exceptions.ConnectionError:
|
||||
pass
|
||||
return server
|
||||
@@ -223,7 +225,7 @@ def update_build_workers(server_data):
|
||||
while unverified_servers and datetime.now() < end_time:
|
||||
for server_ip in list(unverified_servers.keys()): # Iterate over a copy to avoid modification issues
|
||||
try:
|
||||
response = requests.get(f"http://{server_ip}:9001/status", timeout=2)
|
||||
response = requests.get(f"http://{server_ip}:9001/status")
|
||||
response.raise_for_status()
|
||||
server_info = unverified_servers[server_ip] # Get full server details
|
||||
agent_version = response.json().get('agent_version')
|
||||
@@ -254,7 +256,7 @@ def main():
|
||||
parser.add_argument("-restart", type=str, help="Hostname to restart")
|
||||
parser.add_argument("-restart-all", action="store_true", help="Restart all agents")
|
||||
parser.add_argument("-shutdown", type=str, help="Hostname to shutdown")
|
||||
# parser.add_argument("-worker", type=str, help="Update Agents")
|
||||
parser.add_argument("-shutdown-all", action="store_true", help="Restart all agents")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.status:
|
||||
@@ -267,11 +269,11 @@ def main():
|
||||
for server_ip in find_server_ips():
|
||||
restart_agent(server_ip)
|
||||
elif args.shutdown:
|
||||
print(f"Shutting down hostname: {args.shutdown}")
|
||||
try:
|
||||
requests.get(f"http://{args.shutdown}:9001/shutdown")
|
||||
except requests.exceptions.ConnectionError:
|
||||
pass
|
||||
shutdown_agent(args.shutdown)
|
||||
elif args.shutdown_all:
|
||||
print("Shutting down all agents...")
|
||||
for server_ip in find_server_ips():
|
||||
shutdown_agent(server_ip)
|
||||
elif args.delete_cache:
|
||||
delete_cache(get_all_servers_status())
|
||||
elif args.path:
|
||||
@@ -281,12 +283,18 @@ def main():
|
||||
else:
|
||||
print("No path given!")
|
||||
|
||||
def shutdown_agent(hostname):
|
||||
print(f"Shutting down hostname: {hostname}")
|
||||
try:
|
||||
requests.get(f"http://{hostname}:9001/shutdown", timeout=TIMEOUT)
|
||||
except (requests.exceptions.ConnectionError, TimeoutError):
|
||||
pass
|
||||
|
||||
def restart_agent(hostname):
|
||||
print(f"Restarting agent: {hostname}")
|
||||
try:
|
||||
requests.get(f"http://{hostname}:9001/restart")
|
||||
except requests.exceptions.ConnectionError:
|
||||
requests.get(f"http://{hostname}:9001/restart", timeout=TIMEOUT)
|
||||
except (requests.exceptions.ConnectionError, TimeoutError):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user