Skip to content

Commit ba011e7

Browse files
committed
Align transient status handling
1 parent c6ff3ff commit ba011e7

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

src/api/organization/project/branch/__init__.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,9 @@ async def _cleanup_failed_branch_deployment(branch_id: Identifier) -> None:
199199
def _should_update_branch_status(
200200
current: BranchServiceStatus,
201201
derived: BranchServiceStatus,
202-
*,
203-
resize_in_progress: bool = True,
204202
) -> bool:
205203
if current == derived:
206204
return False
207-
if current == BranchServiceStatus.RESIZING:
208-
if not resize_in_progress:
209-
return derived in {
210-
BranchServiceStatus.ACTIVE_HEALTHY,
211-
BranchServiceStatus.ACTIVE_UNHEALTHY,
212-
BranchServiceStatus.STOPPED,
213-
BranchServiceStatus.ERROR,
214-
}
215-
return derived == BranchServiceStatus.ERROR
216205
if current == BranchServiceStatus.STARTING and derived == BranchServiceStatus.STOPPED:
217206
logger.debug("Ignoring STARTING -> STOPPED transition detected by branch status monitor")
218207
return False
@@ -287,12 +276,22 @@ async def refresh_branch_status(branch_id: Identifier) -> BranchServiceStatus:
287276
return new_status
288277

289278

290-
async def _refresh_branch_status(branch: Branch) -> BranchServiceStatus:
279+
def _active_task_status(branch: Branch) -> BranchServiceStatus | None:
280+
"""Return the in-progress status for the running task, or None if idle."""
291281
if branch.control_task_id is not None:
292282
result = perform_control.AsyncResult(str(branch.control_task_id))
293283
action = (result.kwargs or {}).get("action")
294284
if action in _CONTROL_TRANSITION_INITIAL:
295285
return _CONTROL_TRANSITION_INITIAL[action]
286+
if branch.resize_task_id is not None:
287+
return BranchServiceStatus.RESIZING
288+
return None
289+
290+
291+
async def _refresh_branch_status(branch: Branch) -> BranchServiceStatus:
292+
in_progress = _active_task_status(branch)
293+
if in_progress is not None:
294+
return in_progress
296295

297296
current_status = _parse_branch_status(branch.status)
298297
status = deployment_status(branch.id)
@@ -303,8 +302,7 @@ async def _refresh_branch_status(branch: Branch) -> BranchServiceStatus:
303302
status,
304303
)
305304

306-
resize_in_progress = branch.resize_task_id is not None
307-
if _should_update_branch_status(current_status, status, resize_in_progress=resize_in_progress):
305+
if _should_update_branch_status(current_status, status):
308306
branch.set_status(status)
309307
return status
310308

@@ -1879,7 +1877,6 @@ async def resize(
18791877

18801878
task_id = dispatch_resize(str(branch.id), dict(effective_parameters))
18811879

1882-
branch.set_status(BranchServiceStatus.RESIZING)
18831880
branch.resize_task_id = task_id
18841881
await session.commit()
18851882

src/api/organization/project/branch/resize_tasks.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .....database import AsyncSessionLocal
1818
from .....deployment.health import collect_branch_service_health, derive_branch_status_from_services
1919
from .....deployment.resize import resize_cpu_memory, resize_database_pvc, resize_iops, resize_storage_pvc
20-
from .....models.branch import Branch, BranchServiceStatus
20+
from .....models.branch import Branch
2121
from .....models.resources import ResourceLimitsPublic
2222
from .....worker import app
2323
from ...._util.resourcelimit import apply_branch_resource_allocation
@@ -85,11 +85,9 @@ async def _async_finalize_resize(
8585
await _apply_succeeded_fields(session, branch, succeeded)
8686

8787
service_status = await collect_branch_service_health(branch.id)
88-
if branch.status == BranchServiceStatus.RESIZING:
89-
branch.set_status(
90-
derive_branch_status_from_services(service_status, storage_enabled=branch.enable_file_storage)
91-
)
92-
88+
branch.set_status(
89+
derive_branch_status_from_services(service_status, storage_enabled=branch.enable_file_storage)
90+
)
9391
branch.resize_task_id = None
9492
await session.commit()
9593

0 commit comments

Comments
 (0)