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
|
need_nginx_sync = False
|
||||||
|
|
||||||
for area in config.areas:
|
for area in config.areas:
|
||||||
deployed_version = get_deployed_version(area)
|
deployed_version = get_deployed_version(area)['version']
|
||||||
if not deployed_version:
|
if not deployed_version:
|
||||||
print(f' deployed version not found: {area}')
|
print(f' deployed version not found: {area}')
|
||||||
continue
|
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.cloudflare import get_zone_id, set_records_round_robin
|
||||||
from loadbalancer_lib.config import config
|
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
|
from loadbalancer_lib.telegram_ import telegram_send_message
|
||||||
|
|
||||||
|
|
||||||
@@ -46,18 +48,31 @@ def check_or_fix(fix=False):
|
|||||||
|
|
||||||
|
|
||||||
def run_area(area):
|
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:
|
if not version:
|
||||||
print(f' deployed version not found: {area}')
|
print(f' deployed version not found: {area}')
|
||||||
return
|
return
|
||||||
|
|
||||||
print(f' deployed version {area}: {version}')
|
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 = {}
|
results = {}
|
||||||
|
|
||||||
for host_ip in config.http_host_list:
|
for host_ip in config.http_host_list:
|
||||||
try:
|
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
|
results[host_ip] = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
results[host_ip] = False
|
results[host_ip] = False
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from datetime import datetime, timezone
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -27,11 +28,24 @@ def get_versions_for_area(area: str) -> list:
|
|||||||
return sorted(versions)
|
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 = requests.get(f'https://assets.openfreemap.com/deployed_versions/{area}.txt', timeout=30)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
remote_version = r.text.strip()
|
version = r.text.strip()
|
||||||
return remote_version
|
|
||||||
|
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):
|
def check_host_version(domain, host_ip, area, version):
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ def prepare_shared(c):
|
|||||||
pkg_base(c)
|
pkg_base(c)
|
||||||
rclone(c)
|
rclone(c)
|
||||||
|
|
||||||
c.sudo(f'rm -rf {REMOTE_CONFIG}')
|
|
||||||
c.sudo(f'mkdir -p {REMOTE_CONFIG}')
|
c.sudo(f'mkdir -p {REMOTE_CONFIG}')
|
||||||
c.sudo(f'chown ofm:ofm {REMOTE_CONFIG}')
|
c.sudo(f'chown ofm:ofm {REMOTE_CONFIG}')
|
||||||
c.sudo(f'chown ofm:ofm {OFM_DIR}')
|
c.sudo(f'chown ofm:ofm {OFM_DIR}')
|
||||||
|
|||||||
Reference in New Issue
Block a user