mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
implemented relaxed mode for loadbalancer
This commit is contained in:
@@ -19,7 +19,7 @@ def fetch_version_files() -> bool:
|
||||
need_nginx_sync = False
|
||||
|
||||
for area in config.areas:
|
||||
deployed_version = get_deployed_version(area)
|
||||
deployed_version = get_deployed_version(area)['version']
|
||||
if not deployed_version:
|
||||
print(f' deployed version not found: {area}')
|
||||
continue
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from loadbalancer_lib.cloudflare import get_zone_id, set_records_round_robin
|
||||
from loadbalancer_lib.config import config
|
||||
from loadbalancer_lib.shared import check_host_latest, get_deployed_version
|
||||
from loadbalancer_lib.shared import check_host_latest, check_host_version, get_deployed_version
|
||||
from loadbalancer_lib.telegram_ import telegram_send_message
|
||||
|
||||
|
||||
@@ -46,18 +48,31 @@ def check_or_fix(fix=False):
|
||||
|
||||
|
||||
def run_area(area):
|
||||
version = get_deployed_version(area)
|
||||
deployed_data = get_deployed_version(area)
|
||||
version = deployed_data['version']
|
||||
last_modified = deployed_data['last_modified']
|
||||
|
||||
if not version:
|
||||
print(f' deployed version not found: {area}')
|
||||
return
|
||||
|
||||
print(f' deployed version {area}: {version}')
|
||||
|
||||
# using relaxed mode for while the servers are still deploying
|
||||
now = datetime.now(timezone.utc)
|
||||
relaxed_mode = last_modified > now - timedelta(minutes=2)
|
||||
|
||||
results = {}
|
||||
|
||||
for host_ip in config.http_host_list:
|
||||
try:
|
||||
check_host_latest(config.domain_ledns, host_ip, area, version)
|
||||
# don't check latest
|
||||
if relaxed_mode:
|
||||
print('using relaxed mode')
|
||||
check_host_version(config.domain_ledns, host_ip, area, version)
|
||||
else:
|
||||
check_host_latest(config.domain_ledns, host_ip, area, version)
|
||||
|
||||
results[host_ip] = True
|
||||
except Exception as e:
|
||||
results[host_ip] = False
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
@@ -27,11 +28,24 @@ def get_versions_for_area(area: str) -> list:
|
||||
return sorted(versions)
|
||||
|
||||
|
||||
def get_deployed_version(area: str) -> str:
|
||||
def get_deployed_version(area: str) -> dict:
|
||||
r = requests.get(f'https://assets.openfreemap.com/deployed_versions/{area}.txt', timeout=30)
|
||||
r.raise_for_status()
|
||||
remote_version = r.text.strip()
|
||||
return remote_version
|
||||
version = r.text.strip()
|
||||
|
||||
last_modified_str = r.headers.get('Last-Modified')
|
||||
last_modified = parse_http_last_modified(last_modified_str)
|
||||
|
||||
return dict(
|
||||
version=version,
|
||||
last_modified=last_modified,
|
||||
)
|
||||
|
||||
|
||||
def parse_http_last_modified(date_string) -> datetime:
|
||||
parsed_date = datetime.strptime(date_string, '%a, %d %b %Y %H:%M:%S GMT')
|
||||
parsed_date = parsed_date.replace(tzinfo=timezone.utc)
|
||||
return parsed_date
|
||||
|
||||
|
||||
def check_host_version(domain, host_ip, area, version):
|
||||
|
||||
Reference in New Issue
Block a user