Add stopping state
This commit is contained in:
parent
1f52025f97
commit
c56556c3ce
2 changed files with 9 additions and 4 deletions
|
|
@ -162,8 +162,9 @@ class BuildsDb:
|
||||||
def oldest_stopped(self, limit: int) -> list[Build]:
|
def oldest_stopped(self, limit: int) -> list[Build]:
|
||||||
"""Return a list of oldest stopped builds."""
|
"""Return a list of oldest stopped builds."""
|
||||||
rows = self._con.execute(
|
rows = self._con.execute(
|
||||||
"SELECT * FROM builds WHERE status IN (?, ?) ORDER BY last_scaled LIMIT ?",
|
"SELECT * FROM builds WHERE status IN (?, ?, ?) "
|
||||||
(BuildStatus.stopped, BuildStatus.failed, limit),
|
"ORDER BY last_scaled LIMIT ?",
|
||||||
|
(BuildStatus.stopping, BuildStatus.stopped, BuildStatus.failed, limit),
|
||||||
).fetchall()
|
).fetchall()
|
||||||
return [self._build_from_row(row) for row in rows]
|
return [self._build_from_row(row) for row in rows]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ _logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class BuildStatus(str, Enum):
|
class BuildStatus(str, Enum):
|
||||||
stopped = "stopped" # initialization succeeded and 0 replicas
|
stopped = "stopped" # initialization succeeded and 0 replicas
|
||||||
|
stopping = "stopping" # 0 desired replicas but some are still running
|
||||||
starting = "starting" # to initialize or initializing or scaling up
|
starting = "starting" # to initialize or initializing or scaling up
|
||||||
started = "started" # running
|
started = "started" # running
|
||||||
failed = "failed" # initialization failed
|
failed = "failed" # initialization failed
|
||||||
|
|
@ -101,6 +102,9 @@ class Build(BaseModel):
|
||||||
elif init_status == BuildInitStatus.succeeded:
|
elif init_status == BuildInitStatus.succeeded:
|
||||||
replicas = deployment.spec.replicas
|
replicas = deployment.spec.replicas
|
||||||
if not replicas:
|
if not replicas:
|
||||||
|
if deployment.status.replicas:
|
||||||
|
return BuildStatus.stopping
|
||||||
|
else:
|
||||||
return BuildStatus.stopped
|
return BuildStatus.stopped
|
||||||
else:
|
else:
|
||||||
if deployment.status.ready_replicas == replicas:
|
if deployment.status.ready_replicas == replicas:
|
||||||
|
|
@ -163,7 +167,7 @@ class Build(BaseModel):
|
||||||
_logger.info(f"Marking failed {self} for reinitialization.")
|
_logger.info(f"Marking failed {self} for reinitialization.")
|
||||||
await k8s.delete_job(self.name, job_kind=k8s.DeploymentMode.initialize)
|
await k8s.delete_job(self.name, job_kind=k8s.DeploymentMode.initialize)
|
||||||
await self._patch(init_status=BuildInitStatus.todo, desired_replicas=0)
|
await self._patch(init_status=BuildInitStatus.todo, desired_replicas=0)
|
||||||
elif self.status == BuildStatus.stopped:
|
elif self.status in (BuildStatus.stopped, BuildStatus.stopping):
|
||||||
_logger.info(f"Starting {self} that was last scaled on {self.last_scaled}.")
|
_logger.info(f"Starting {self} that was last scaled on {self.last_scaled}.")
|
||||||
await self._patch(desired_replicas=1)
|
await self._patch(desired_replicas=1)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue