async def METHOD_NAME(self) -> None:
    """
    Flush all events to the posthog server.
    """
    # check, if we need to fetch or refresh the public api key
    if not self.last_fetched:
        await self.refresh_public_api_key()
        sd = self.system_data
        self.client.identify(sd.system_id, {"run_id": self.run_id, "created_at": sd.created_at})
    elif (utc() - self.last_fetched) > timedelta(hours=1):
        await self.refresh_public_api_key()
    # acquire the lock, send all events to the client and clear the queue
    async with self.lock:
        for event in self.queue:
            self.client.capture(
                distinct_id=self.system_data.system_id,
                event=event.kind,
                properties={
                    **event.context,
                    **event.counters,
                    "source": event.system,
                    "run_id": self.run_id,
                },
                timestamp=event.at,
            )
        self.queue.clear()