fix wrong instances when using docker mode and add delay to docker-configs tests

This commit is contained in:
florian 2023-08-08 11:26:22 +02:00
parent 6047a43358
commit c00157ef32
No known key found for this signature in database
GPG key ID: 3D80806F12602A7C
2 changed files with 27 additions and 1 deletions

View file

@ -1,6 +1,7 @@
{
"name": "docker-configs",
"kinds": ["docker"],
"delay": 30,
"timeout": 60,
"tests": [
{

View file

@ -175,6 +175,25 @@ def dict_to_frozenset(d):
return frozenset((k, dict_to_frozenset(v)) for k, v in d.items())
return d
def api_to_instance(api):
hostname_port = api.endpoint.replace("http://", "").replace("https://", "").replace("/", "").split(":")
return {
"hostname": hostname_port[0],
"env": {
"API_HTTP_PORT": int(hostname_port[1]),
"API_SERVER_NAME": api.host
}
}
def update_docker_instances(sc, db, force=False):
current_apis = set(sc.apis)
sc.auto_setup()
if force or current_apis != set(sc.apis):
new_instances = []
for api in sc.apis:
new_instances.append(api_to_instance(api))
return db.update_instances(new_instances)
return ""
if __name__ == "__main__":
try:
@ -290,9 +309,15 @@ if __name__ == "__main__":
# Instantiate scheduler
SCHEDULER = JobScheduler(env.copy() | environ.copy(), logger, INTEGRATION)
if INTEGRATION in ("Swarm", "Kubernetes", "Autoconf", "Docker"):
if INTEGRATION in ("Swarm", "Kubernetes", "Autoconf"):
# Automatically setup the scheduler apis
SCHEDULER.auto_setup()
elif INTEGRATION == "Docker":
err = update_docker_instances(SCHEDULER, db, force=True)
if err:
logger.error(
f"Couldn't save instances to database: {err}",
)
scheduler_first_start = db.is_scheduler_first_start()