diff --git a/bin/capture_manager.py b/bin/capture_manager.py index 7e958c9..7d97366 100755 --- a/bin/capture_manager.py +++ b/bin/capture_manager.py @@ -26,21 +26,23 @@ def __init__(self, loglevel: Optional[int]=None): self.lacus = Lacus() async def clear_dead_captures(self): - ongoing = [capture.get_name() for capture in self.captures] + ongoing = {capture.get_name(): capture for capture in self.captures} max_capture_time = get_config('generic', 'max_capture_time') oldest_start_time = datetime.now() - timedelta(seconds=max_capture_time) for expected_uuid, start_time in self.lacus.monitoring.get_ongoing_captures(): - if expected_uuid not in ongoing: + if expected_uuid not in ongoing.keys(): self.lacus.core.clear_capture(expected_uuid, 'Capture not in the list of tasks, it has been canceled.') elif start_time < oldest_start_time: self.logger.warning(f'{expected_uuid} has been running for too long. Started at {start_time}.') - for capture in self.captures: - if capture.get_name() == expected_uuid: - if sys.version_info >= (3, 9): - capture.cancel(f'Capture as been running for more than {max_capture_time}s.') - else: - capture.cancel() - break + capture = ongoing[expected_uuid] + if sys.version_info >= (3, 9): + capture.cancel(f'Capture as been running for more than {max_capture_time}s.') + else: + capture.cancel() + try: + await capture + except asyncio.CancelledError: + self.logger.warning(f'{expected_uuid} is canceled now.') async def _to_run_forever_async(self): await self.clear_dead_captures() diff --git a/poetry.lock b/poetry.lock index fb7d6f6..f13d530 100644 --- a/poetry.lock +++ b/poetry.lock @@ -885,18 +885,18 @@ format-nongpl = ["fqdn", "idna", "isoduration", "jsonpointer (>1.13)", "rfc3339- [[package]] name = "lacuscore" -version = "1.7.4" +version = "1.7.5" description = "Core of Lacus, usable as a module" optional = false python-versions = ">=3.8,<4.0" files = [ - {file = "lacuscore-1.7.4-py3-none-any.whl", hash = "sha256:1f67b131c6b2fe9ee36ada94fa1663ca7d10d52ca330f42d1d86ddcd33718e94"}, - {file = "lacuscore-1.7.4.tar.gz", hash = "sha256:b4017f59122386c4b4a7632f67aa06050056b677636b4ef83709451fbbe1ad3f"}, + {file = "lacuscore-1.7.5-py3-none-any.whl", hash = "sha256:9daefe14ad0344a01c6dae32a700c4b5f6449667c2bad821743f45bb170470e9"}, + {file = "lacuscore-1.7.5.tar.gz", hash = "sha256:6ea26aebea752808262b9f84f13169b184a406dc30ee4c09f3d8e1c26051a3ce"}, ] [package.dependencies] defang = ">=0.5.3,<0.6.0" -playwrightcapture = {version = ">=1.22.3,<2.0.0", extras = ["recaptcha"]} +playwrightcapture = {version = ">=1.22.4,<2.0.0", extras = ["recaptcha"]} redis = {version = ">=5.0.1,<6.0.0", extras = ["hiredis"]} requests = ">=2.31.0,<3.0.0" ua-parser = ">=0.18.0,<0.19.0" @@ -1268,13 +1268,13 @@ test = ["pytest"] [[package]] name = "playwrightcapture" -version = "1.22.3" +version = "1.22.4" description = "A simple library to capture websites using playwright" optional = false python-versions = ">=3.8,<4.0" files = [ - {file = "playwrightcapture-1.22.3-py3-none-any.whl", hash = "sha256:9105fb540080726ec9ffd2a132a6a321e5c9b6fb94b16907c0d27c98b1e8dcf5"}, - {file = "playwrightcapture-1.22.3.tar.gz", hash = "sha256:a7176a113b4327a591f24a7f07ad9e0d9fa751dca46449f1dfdf9968fe692585"}, + {file = "playwrightcapture-1.22.4-py3-none-any.whl", hash = "sha256:517622d1a691cb6069974fa70edac2224fb4d801fd49391236d26ed0e43a35b4"}, + {file = "playwrightcapture-1.22.4.tar.gz", hash = "sha256:4ba6489af19a7eff5656f03ab6061b57a5c347724fe4c97adb75bc87a74630f0"}, ] [package.dependencies] @@ -1286,12 +1286,12 @@ pydub = {version = ">=0.25.1,<0.26.0", optional = true, markers = "extra == \"re pytz = {version = ">=2023.3.post1,<2024.0", markers = "python_version < \"3.9\""} requests = {version = ">=2.31.0,<3.0.0", extras = ["socks"], optional = true, markers = "extra == \"recaptcha\""} setuptools = ">=69.0.2,<70.0.0" -SpeechRecognition = {version = ">=3.10.0,<4.0.0", optional = true, markers = "extra == \"recaptcha\""} +SpeechRecognition = {version = ">=3.10.1,<4.0.0", optional = true, markers = "extra == \"recaptcha\""} tzdata = ">=2023.3,<2024.0" w3lib = ">=2.1.2,<3.0.0" [package.extras] -recaptcha = ["SpeechRecognition (>=3.10.0,<4.0.0)", "pydub (>=0.25.1,<0.26.0)", "requests[socks] (>=2.31.0,<3.0.0)"] +recaptcha = ["SpeechRecognition (>=3.10.1,<4.0.0)", "pydub (>=0.25.1,<0.26.0)", "requests[socks] (>=2.31.0,<3.0.0)"] [[package]] name = "prompt-toolkit" @@ -1914,4 +1914,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "3d8fb11ebb81806a03707223820a4cb7bcc8b47565876f0144cc84bf9e15805d" +content-hash = "42ff8a82417936022645e742adb513ad5a3c005b8bfdf0c7dc69a7d2163d66d8" diff --git a/pyproject.toml b/pyproject.toml index 578a48c..d3f6643 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ redis = {version = "^5.0.1", extras = ["hiredis"]} flask-restx = "^1.2.0" werkzeug = "^2.3.8" gunicorn = "^21.2.0" -lacuscore = "^1.7.4" +lacuscore = "^1.7.5" rich = "^13.7.0" psutil = "^5.9.6"