Compare commits

...

2 Commits

Author SHA1 Message Date
7cddc059b5
worker: Fixed count sites function
All checks were successful
Build Docker / Build Bot (push) Successful in 25s
Build Docker / Build Master (push) Successful in 26s
2023-08-25 11:56:06 +10:00
dd4d97ffc9
main: Fixed list workers 2023-08-25 11:55:51 +10:00
2 changed files with 10 additions and 11 deletions

View File

@ -174,10 +174,14 @@ def list_workers():
resp=requests.get("http://"+worker.split(':')[1].strip('\n') + ":5000/status",timeout=2) resp=requests.get("http://"+worker.split(':')[1].strip('\n') + ":5000/status",timeout=2)
if (resp.status_code != 200): if (resp.status_code != 200):
online=False online=False
worker_list.append({'worker': worker.split(':')[0],'ip': worker.split(':')[1].strip('\n'), 'online': online, 'sites': 0, 'ready': 0}) worker_list.append({'worker': worker.split(':')[0],'ip': worker.split(':')[1].strip('\n'), 'online': online, 'sites': 0, 'status': 'offline'})
continue continue
sites = resp.json()['num_sites'] sites = resp.json()['num_sites']
worker_list.append({'worker': worker.split(':')[0],'ip': worker.split(':')[1].strip('\n'), 'online': online, 'sites': sites, 'ready': 1}) availability = resp.json()['availability']
if availability == True:
worker_list.append({'worker': worker.split(':')[0],'ip': worker.split(':')[1].strip('\n'), 'online': online, 'sites': sites, 'status': 'ready'})
else:
worker_list.append({'worker': worker.split(':')[0],'ip': worker.split(':')[1].strip('\n'), 'online': online, 'sites': sites, 'status': 'full'})
if len(worker_list) == 0: if len(worker_list) == 0:
return jsonify({'error': 'No workers available', 'success': 'false'}) return jsonify({'error': 'No workers available', 'success': 'false'})

View File

@ -67,16 +67,11 @@ def ping():
return 'pong' return 'pong'
def get_sites_count(): def get_sites_count():
# If file doesn't exist, create it # Get number of files in nginx/sites
try: dir = os.listdir('/etc/nginx/sites-available')
sites_file = open('sites.txt', 'r') num_Sites = len(dir) - 1
except FileNotFoundError:
sites_file = open('sites.txt', 'w')
sites_file.close()
sites_file = open('sites.txt', 'r')
print(sites_file.readlines())
# Return number of lines in file # Return number of lines in file
return len(sites_file.readlines()) return num_Sites
def site_exists(domain): def site_exists(domain):
# If file doesn't exist, create it # If file doesn't exist, create it