Skip to content

Commit

Permalink
Fix AsyncioTelemetryManager to avoid creating a task every second
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Feb 26, 2024
1 parent 4c03ecd commit 01515b1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pubnub/pubnub_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,14 +794,18 @@ async def wait_for_presence_on(self, *channel_names):
class AsyncioTelemetryManager(TelemetryManager):
def __init__(self):
TelemetryManager.__init__(self)
self._timer = AsyncioPeriodicCallback(
self._start_clean_up_timer,
self.CLEAN_UP_INTERVAL * self.CLEAN_UP_INTERVAL_MULTIPLIER,
asyncio.get_event_loop())
self._timer.start()
self.loop = asyncio.get_event_loop()
self._schedule_next_cleanup()

async def _start_clean_up_timer(self):
def _schedule_next_cleanup(self):
self._timer = self.loop.call_later(
self.CLEAN_UP_INTERVAL * self.CLEAN_UP_INTERVAL_MULTIPLIER / 1000,
self._clean_up_schedule_next
)

def _clean_up_schedule_next(self):
self.clean_up_telemetry_data()
self._schedule_next_cleanup()

def _stop_clean_up_timer(self):
self._timer.stop()
self._timer.cancel()

0 comments on commit 01515b1

Please sign in to comment.