Skip to content

Commit

Permalink
chg: Improve handling of canceled captures
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Dec 8, 2023
1 parent 61e9be8 commit 7c0a7af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
20 changes: 11 additions & 9 deletions bin/capture_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 10 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 7c0a7af

Please sign in to comment.