Skip to content
Snippets Groups Projects
Verified Commit c55303d6 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Implement concurrency for group routines

parent cacd4837
No related branches found
No related tags found
No related merge requests found
import concurrent.futures
from dataclasses import dataclass, field from dataclasses import dataclass, field
from hashlib import sha1 from hashlib import sha1
from socket import getfqdn 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.parse import urlencode
from urllib.request import urlopen from urllib.request import urlopen
from uuid import uuid1 from uuid import uuid1
...@@ -97,19 +98,36 @@ class BigBlueButtonGroup: ...@@ -97,19 +98,36 @@ class BigBlueButtonGroup:
name: str name: str
apis: dict = field(default_factory=dict) apis: dict = field(default_factory=dict)
workers: int = 10
def new(self, name: str, *args, **kwargs) -> BigBlueButton: def new(self, name: str, *args, **kwargs) -> BigBlueButton:
bbb = BigBlueButton(self, name, *args, **kwargs) bbb = BigBlueButton(self, name, *args, **kwargs)
return bbb return bbb
def get_meetings(self) -> Dict[str, "Meeting"]: def _foreach(self, method: str, *args, **kwargs) -> Dict[str, Any]:
res = {} 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 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]: def ssh_command(self, command: Sequence[str], input: Optional[str] = None) -> Dict[str, subprocess.CompletedProcess]:
res = {} res = self._foreach("ssh_command", command, input)
for name, bbb in self.apis.items():
res[name] = bbb.ssh_command(command, input)
return res return res
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment