add async shutdown cleanup and review fixes
Agent-Logs-Url: https://github.com/rudolf1/brencher/sessions/9e719b58-ad2a-4eca-99bf-43c750f71a72 Co-authored-by: rudolf1 <5525769+rudolf1@users.noreply.github.com>
This commit is contained in:
co-authored by
rudolf1
parent
6f3dd6ebd8
commit
1acea85934
@@ -105,6 +105,7 @@ class App:
|
||||
has_error = await asyncio.to_thread(processing.process_all_jobs, list(self.environments.values()), emit)
|
||||
if self.shutdown_event.is_set():
|
||||
return
|
||||
# Skip the wait when a newer update arrived while the current processing pass was running.
|
||||
if self.environment_update_version != update_version:
|
||||
continue
|
||||
timeout = 5 if has_error else 60
|
||||
@@ -138,6 +139,7 @@ class App:
|
||||
asyncio.run(self.runHeadlessAsync())
|
||||
|
||||
async def _run_web_server(self, web_app: Any) -> None:
|
||||
"""Raise a sentinel exception when the server stops so TaskGroup cancels processing."""
|
||||
await web_app.start_async()
|
||||
raise _WebServerStopped()
|
||||
|
||||
|
||||
@@ -96,6 +96,7 @@ class WebApp:
|
||||
|
||||
def _schedule_async(self, coro: Any) -> None:
|
||||
if self._event_loop is None or not self._event_loop.is_running():
|
||||
logger.warning("Dropping scheduled coroutine because the web event loop is not running")
|
||||
coro.close()
|
||||
return
|
||||
try:
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import asyncio
|
||||
import sys
|
||||
import types
|
||||
from typing import Callable
|
||||
|
||||
import pytest
|
||||
|
||||
from enironment import Environment
|
||||
import processing
|
||||
from app import App
|
||||
|
||||
@@ -17,10 +19,10 @@ class TestAppAsyncio:
|
||||
loop = asyncio.get_running_loop()
|
||||
web_app_args: dict[str, object] = {}
|
||||
|
||||
def fake_process_all_jobs(environments: object, onupdate: object) -> bool:
|
||||
def fake_process_all_jobs(environments: list[Environment], onupdate: Callable[[], None]) -> bool:
|
||||
nonlocal process_calls
|
||||
process_calls += 1
|
||||
assert callable(onupdate)
|
||||
assert environments == []
|
||||
onupdate()
|
||||
loop.call_soon_threadsafe(processing_started.set)
|
||||
return False
|
||||
|
||||
@@ -59,6 +59,7 @@ class TestDockerContainer:
|
||||
processing.cancel()
|
||||
with suppress(asyncio.CancelledError):
|
||||
await processing
|
||||
assert processing.cancelled()
|
||||
|
||||
# TODO Verify DockerContainerDeploy step status is running and has correct image and ports
|
||||
# {
|
||||
|
||||
Reference in New Issue
Block a user