2024-08-22 02:47:16 +03:00
|
|
|
import concurrent.futures
|
|
|
|
|
|
|
|
|
|
|
|
class Network:
|
|
|
|
def __init__(self, name, sequencers):
|
|
|
|
self.name = name
|
|
|
|
self.sequencers = sequencers
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
def _update(sequencer):
|
|
|
|
sequencer.update()
|
|
|
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
|
|
list(executor.map(_update, self.sequencers))
|
|
|
|
|
|
|
|
def get_sequencer_by_id(self, sequencer_id: str):
|
|
|
|
return next(
|
|
|
|
(
|
|
|
|
sequencer
|
|
|
|
for sequencer in self.sequencers
|
|
|
|
if sequencer.sequencer_id == sequencer_id
|
|
|
|
),
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
|
|
|
|
def find_conductor_leader(self):
|
|
|
|
return next(
|
|
|
|
(sequencer for sequencer in self.sequencers if sequencer.conductor_leader),
|
|
|
|
None,
|
|
|
|
)
|
2024-09-05 00:34:03 +03:00
|
|
|
|
|
|
|
def find_active_sequencer(self):
|
|
|
|
return next(
|
|
|
|
(sequencer for sequencer in self.sequencers if sequencer.sequencer_active),
|
|
|
|
None,
|
|
|
|
)
|