feat(jobs): name job containers after the job instead of its id
This commit is contained in:
@@ -5,6 +5,7 @@ periodic schedule/reconcile loop.
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import re
|
||||
from datetime import datetime
|
||||
from threading import RLock
|
||||
from typing import Optional
|
||||
@@ -129,6 +130,18 @@ def is_registry_image(image: Optional[str]) -> bool:
|
||||
return bool(image) and image.split("/", 1)[0] == registry_host()
|
||||
|
||||
|
||||
def container_name(definition: JobDefinition, run: JobRun) -> str:
|
||||
slug = definition.name.lower()
|
||||
slug = (
|
||||
slug.replace("ä", "ae")
|
||||
.replace("ö", "oe")
|
||||
.replace("ü", "ue")
|
||||
.replace("ß", "ss")
|
||||
)
|
||||
slug = re.sub(r"[^a-z0-9]+", "-", slug).strip("-")[:40].strip("-")
|
||||
return f"{slug or 'job'}-run-{run.id}"
|
||||
|
||||
|
||||
def resolve_command(definition: JobDefinition):
|
||||
return definition.command or None
|
||||
|
||||
@@ -191,7 +204,7 @@ def start_run(
|
||||
command=resolve_command(definition),
|
||||
environment=resolve_environment(definition),
|
||||
detach=True,
|
||||
name=f"background-job-{definition.id}-run-{run.id}",
|
||||
name=container_name(definition, run),
|
||||
remove=False,
|
||||
)
|
||||
run.container_id = container.id
|
||||
|
||||
Reference in New Issue
Block a user