|
97 | 97 | _CONTROL_TO_POWER_STATE, |
98 | 98 | _CONTROL_TRANSITION_INITIAL, |
99 | 99 | dispatch_control, |
| 100 | + perform_control, |
100 | 101 | ) |
101 | 102 | from .resize_tasks import dispatch_resize |
102 | 103 | from .tasks import task_api |
@@ -287,6 +288,12 @@ async def refresh_branch_status(branch_id: Identifier) -> BranchServiceStatus: |
287 | 288 |
|
288 | 289 |
|
289 | 290 | 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 | + |
290 | 297 | current_status = _parse_branch_status(branch.status) |
291 | 298 | status = deployment_status(branch.id) |
292 | 299 |
|
@@ -1932,19 +1939,16 @@ async def control_branch( |
1932 | 1939 | ): |
1933 | 1940 | action = request.scope["route"].name.split(":")[-1] |
1934 | 1941 | 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 |
1940 | 1944 | await session.commit() |
1941 | 1945 |
|
1942 | 1946 | task_url = url_path_for( |
1943 | 1947 | request, |
1944 | 1948 | "organizations:projects:branch:tasks:detail", |
1945 | 1949 | organization_id=await organization.awaitable_attrs.id, |
1946 | 1950 | 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, |
1948 | 1952 | task_id=task_id, |
1949 | 1953 | ) |
1950 | 1954 | return Response(status_code=202, headers={"Location": task_url}) |
|
0 commit comments