agent: Add BatchableTelemMixin

Adds an implementation as a mixin of the two methods specified by
IBatchableTelem.
This commit is contained in:
Mike Salvatore 2021-06-24 12:09:30 -04:00
parent f2a940a4e0
commit 8e40e44263
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
from typing import Iterable
from infection_monkey.telemetry.i_batchable_telem import IBatchableTelem
class BatchableTelemMixin:
"""
Implements the IBatchableTelem interface methods using a list.
"""
@property
def _telemetry_entries(self):
if not hasattr(self, "_list"):
self._list = []
return self._list
def get_telemetry_entries(self) -> Iterable:
return self._telemetry_entries
def add_telemetry_to_batch(self, telemetry: IBatchableTelem):
self._telemetry_entries.extend(telemetry.get_telemetry_entries())