Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AsyncioTelemetryManager to avoid creating a task every second #181

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading