Skip to content

Commit d427221

Browse files
committed
fixup! Convert branch state management to jobs
1 parent 0673a25 commit d427221

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
_CONTROL_TO_POWER_STATE,
9898
_CONTROL_TRANSITION_INITIAL,
9999
dispatch_control,
100+
perform_control,
100101
)
101102
from .resize_tasks import dispatch_resize
102103
from .tasks import task_api
@@ -287,6 +288,12 @@ async def refresh_branch_status(branch_id: Identifier) -> BranchServiceStatus:
287288

288289

289290
async def _refresh_branch_status(branch: Branch) -> BranchServiceStatus:
291+
if branch.control_task_id is not None:
292+
result = perform_control.AsyncResult(str(branch.control_task_id))
293+
action = (result.kwargs or {}).get("action")
294+
if action in _CONTROL_TRANSITION_INITIAL:
295+
return _CONTROL_TRANSITION_INITIAL[action]
296+
290297
current_status = _parse_branch_status(branch.status)
291298
status = deployment_status(branch.id)
292299

@@ -1932,19 +1939,16 @@ async def control_branch(
19321939
):
19331940
action = request.scope["route"].name.split(":")[-1]
19341941
assert action in _CONTROL_TO_POWER_STATE
1935-
branch_in_session = await session.merge(branch)
1936-
await _set_branch_status(session, branch_in_session, _CONTROL_TRANSITION_INITIAL[action])
1937-
1938-
task_id = dispatch_control(str(branch_in_session.id), action)
1939-
branch_in_session.control_task_id = task_id
1942+
task_id = dispatch_control(str(branch.id), action)
1943+
branch.control_task_id = task_id
19401944
await session.commit()
19411945

19421946
task_url = url_path_for(
19431947
request,
19441948
"organizations:projects:branch:tasks:detail",
19451949
organization_id=await organization.awaitable_attrs.id,
19461950
project_id=await project.awaitable_attrs.id,
1947-
branch_id=await branch_in_session.awaitable_attrs.id,
1951+
branch_id=await branch.awaitable_attrs.id,
19481952
task_id=task_id,
19491953
)
19501954
return Response(status_code=202, headers={"Location": task_url})

0 commit comments

Comments
 (0)