Verified Commit c55303d6 authored by Dominik George's avatar Dominik George 🍻

Implement concurrency for group routines

parent cacd4837
import concurrent.futures
from dataclasses import dataclass, field
from hashlib import sha1
from socket import getfqdn
from typing import Dict, Optional, Sequence
from typing import Any, Callable, Dict, Optional, Sequence
from urllib.parse import urlencode
from urllib.request import urlopen
from uuid import uuid1
......@@ -97,19 +98,36 @@ class BigBlueButtonGroup:
name: str
apis: dict = field(default_factory=dict)
workers: int = 10
def new(self, name: str, *args, **kwargs) -> BigBlueButton:
bbb = BigBlueButton(self, name, *args, **kwargs)
return bbb
def get_meetings(self) -> Dict[str, "Meeting"]:
def _foreach(self, method: str, *args, **kwargs) -> Dict[str, Any]:
res = {}
for name, bbb in self.apis.items():
res.update(bbb.get_meetings())
with concurrent.futures.ThreadPoolExecutor(max_workers=self.workers) as pool:
futures = {}
for name, bbb in self.apis.items():
fn = getattr(bbb, method)
futures[pool.submit(fn, *args, **kwargs)] = name
for future in concurrent.futures.as_completed(futures):
name = futures[future]
res[name] = future.result()
return res
def get_meetings(self) -> Dict[str, "Meeting"]:
res = self._foreach("get_meetings")
meetings = {}
for name in res:
meetings.update(res[name])
return meetings
def ssh_command(self, command: Sequence[str], input: Optional[str] = None) -> Dict[str, subprocess.CompletedProcess]:
res = {}
for name, bbb in self.apis.items():
res[name] = bbb.ssh_command(command, input)
res = self._foreach("ssh_command", command, input)
return res
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment