Show max values in /status api
This commit is contained in:
parent
28c109de6e
commit
8f7aa98224
3 changed files with 22 additions and 7 deletions
|
|
@ -14,8 +14,11 @@ router = APIRouter()
|
||||||
|
|
||||||
class Status(BaseModel):
|
class Status(BaseModel):
|
||||||
deployed: int
|
deployed: int
|
||||||
|
max_deployed: int
|
||||||
running: int
|
running: int
|
||||||
|
max_running: int
|
||||||
starting: int
|
starting: int
|
||||||
|
max_starting: int
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
|
|
||||||
|
|
@ -39,14 +39,26 @@ class Controller:
|
||||||
def running(self) -> int:
|
def running(self) -> int:
|
||||||
return self.db.count_by_statuses([BuildStatus.started, BuildStatus.starting])
|
return self.db.count_by_statuses([BuildStatus.started, BuildStatus.starting])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_running(self) -> int:
|
||||||
|
return settings.max_running
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def starting(self) -> int:
|
def starting(self) -> int:
|
||||||
return self.db.count_by_statuses([BuildStatus.starting])
|
return self.db.count_by_statuses([BuildStatus.starting])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_starting(self) -> int:
|
||||||
|
return settings.max_starting
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def deployed(self) -> int:
|
def deployed(self) -> int:
|
||||||
return self.db.count_all()
|
return self.db.count_all()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_deployed(self) -> int:
|
||||||
|
return settings.max_deployed
|
||||||
|
|
||||||
def _wakeup(self) -> None:
|
def _wakeup(self) -> None:
|
||||||
self._wakeup_event.set()
|
self._wakeup_event.set()
|
||||||
self._wakeup_event.clear()
|
self._wakeup_event.clear()
|
||||||
|
|
@ -71,8 +83,8 @@ class Controller:
|
||||||
await self._wakeup_event.wait()
|
await self._wakeup_event.wait()
|
||||||
while True:
|
while True:
|
||||||
can_start = max(
|
can_start = max(
|
||||||
settings.max_running - self.running,
|
self.max_running - self.running,
|
||||||
settings.max_starting - self.starting,
|
self.max_starting - self.starting,
|
||||||
)
|
)
|
||||||
if can_start <= 0:
|
if can_start <= 0:
|
||||||
break # no capacity for now, back to sleep
|
break # no capacity for now, back to sleep
|
||||||
|
|
@ -89,7 +101,7 @@ class Controller:
|
||||||
while True:
|
while True:
|
||||||
await self._wakeup_event.wait()
|
await self._wakeup_event.wait()
|
||||||
while True:
|
while True:
|
||||||
can_stop = self.running - settings.max_running
|
can_stop = self.running - self.max_running
|
||||||
if can_stop <= 0:
|
if can_stop <= 0:
|
||||||
break # nothing to top for now, back to sleep
|
break # nothing to top for now, back to sleep
|
||||||
to_stop = self.db.oldest_started(limit=can_stop)
|
to_stop = self.db.oldest_started(limit=can_stop)
|
||||||
|
|
@ -105,7 +117,7 @@ class Controller:
|
||||||
while True:
|
while True:
|
||||||
await self._wakeup_event.wait()
|
await self._wakeup_event.wait()
|
||||||
while True:
|
while True:
|
||||||
can_undeploy = self.deployed - settings.max_deployed
|
can_undeploy = self.deployed - self.max_deployed
|
||||||
if can_undeploy <= 0:
|
if can_undeploy <= 0:
|
||||||
break # nothing to undeploy for now, back to sleep
|
break # nothing to undeploy for now, back to sleep
|
||||||
to_undeploy = self.db.oldest_stopped(limit=can_undeploy)
|
to_undeploy = self.db.oldest_stopped(limit=can_undeploy)
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ class Settings(BaseSettings):
|
||||||
admin_user: str
|
admin_user: str
|
||||||
admin_passwd: str
|
admin_passwd: str
|
||||||
supported_repos: set[str]
|
supported_repos: set[str]
|
||||||
max_starting: int = 4
|
max_starting: int = 2
|
||||||
max_running: int = 10
|
max_running: int = 4
|
||||||
max_deployed: int = 20
|
max_deployed: int = 10
|
||||||
build_namespace: str
|
build_namespace: str
|
||||||
build_pghost: str
|
build_pghost: str
|
||||||
build_pgport: str
|
build_pgport: str
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue