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]:
|
||||
"""Return a list of oldest stopped builds."""
|
||||
rows = self._con.execute(
|
||||
"SELECT * FROM builds WHERE status IN (?, ?) ORDER BY last_scaled LIMIT ?",
|
||||
(BuildStatus.stopped, BuildStatus.failed, limit),
|
||||
"SELECT * FROM builds WHERE status IN (?, ?, ?) "
|
||||
"ORDER BY last_scaled LIMIT ?",
|
||||
(BuildStatus.stopping, BuildStatus.stopped, BuildStatus.failed, limit),
|
||||
).fetchall()
|
||||
return [self._build_from_row(row) for row in rows]
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ _logger = logging.getLogger(__name__)
|
|||
|
||||
class BuildStatus(str, Enum):
|
||||
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
|
||||
started = "started" # running
|
||||
failed = "failed" # initialization failed
|
||||
|
|
@ -101,6 +102,9 @@ class Build(BaseModel):
|
|||
elif init_status == BuildInitStatus.succeeded:
|
||||
replicas = deployment.spec.replicas
|
||||
if not replicas:
|
||||
if deployment.status.replicas:
|
||||
return BuildStatus.stopping
|
||||
else:
|
||||
return BuildStatus.stopped
|
||||
else:
|
||||
if deployment.status.ready_replicas == replicas:
|
||||
|
|
@ -163,7 +167,7 @@ class Build(BaseModel):
|
|||
_logger.info(f"Marking failed {self} for reinitialization.")
|
||||
await k8s.delete_job(self.name, job_kind=k8s.DeploymentMode.initialize)
|
||||
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}.")
|
||||
await self._patch(desired_replicas=1)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue