I store some temporary data in a database linked to a web socket. After a server reboot, the web sockets die and I want to delete all data from the corresponding table. Tell me where ideologically this should be done or such data should not be stored in the database at all?
I tried putting this block in AppConfig.ready but the console warning says it's the wrong place.
from django.apps import AppConfig
class GameConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'game'
def ready(self) -> None:
LobbySetting = self.get_model('LobbySetting')
LobbySetting.objects.all().delete()
Warning in console:
RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.
warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)
job schedulerto clear all data that’s one week old (or similar).