return f"KresID({self})"
def __hash__(self) -> int:
+ if self._repr:
+ return hash(self._repr)
return self._id
def __eq__(self, o: object) -> bool:
- return isinstance(o, KresID) and self._id == o._id
+ if isinstance(o, KresID):
+ ret = self._id == o._id
+ if self._repr:
+ ret |= self._repr == o._repr
+ return ret
+ return False
try:
# gather current state
detected_subprocesses = await self._controller.get_subprocess_status()
- worker_ids = [x.id for x in self._workers]
+ expected_ids = [x.id for x in self._workers]
+ if self._gc:
+ expected_ids.append(self._gc.id)
invoke_callback = False
- for w in worker_ids:
- if w not in detected_subprocesses:
- logger.error("Expected to find subprocess with id '%s' in the system, but did not.", w)
+ for eid in expected_ids:
+ if eid not in detected_subprocesses:
+ logger.error("Expected to find subprocess with id '%s' in the system, but did not.", eid)
invoke_callback = True
continue
- if detected_subprocesses[w] is SubprocessStatus.FAILED:
- logger.error("Subprocess '%s' is failed.", w)
+ if detected_subprocesses[eid] is SubprocessStatus.FAILED:
+ logger.error("Subprocess '%s' is failed.", eid)
invoke_callback = True
continue
- if detected_subprocesses[w] is SubprocessStatus.UNKNOWN:
- logger.warning("Subprocess '%s' is in unknown state!", w)
+ if detected_subprocesses[eid] is SubprocessStatus.UNKNOWN:
+ logger.warning("Subprocess '%s' is in unknown state!", eid)
except asyncio.CancelledError:
raise
async def create_subprocess(self, subprocess_config: KresConfig, subprocess_type: SubprocessType) -> Subprocess:
assert self._controller_config is not None
- custom_id = KresID.from_string("gc") if subprocess_type == SubprocessType.GC else None
+ custom_id = KresID.from_string(GC_SERVICE_NAME) if subprocess_type == SubprocessType.GC else None
return SystemdSubprocess(subprocess_config, subprocess_type, self._systemd_type, custom_id=custom_id)
async def get_subprocess_status(self) -> Dict[KresID, SubprocessStatus]:
import logging
import os
+import re
from enum import Enum, auto
from threading import Thread
from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar
logger = logging.getLogger(__name__)
-GC_SERVICE_NAME = "kresd_gc.service"
+_PREFIX = "mkres"
+GC_SERVICE_NAME = f"{_PREFIX}_cache_gc.service"
+KRESD_SERVICE_PATTERN = re.compile(rf"^{_PREFIX}d_([0-9]+).service$")
def kres_id_from_service_name(service_name: str) -> KresID:
- v = service_name.replace("kresd_", "").replace(".service", "")
- return KresID.from_string(v)
+ kid = KRESD_SERVICE_PATTERN.search(service_name)
+ if kid:
+ return KresID.from_string(kid.groups()[0])
+ return KresID.from_string(service_name)
def service_name_from_kres_id(kid: KresID) -> str:
- return f"kresd_{kid}.service"
+ rep = str(kid)
+ if rep.isnumeric():
+ return f"{_PREFIX}d_{rep}.service"
+ return rep
def is_service_name_ours(service_name: str) -> bool:
is_ours = service_name == GC_SERVICE_NAME
- is_ours |= service_name.startswith("kresd_") and service_name.endswith(".service")
+ is_ours |= bool(KRESD_SERVICE_PATTERN.match(service_name))
return is_ours