88from django .conf import settings
99from django .core .exceptions import ImproperlyConfigured
1010from django .db import connection , transaction
11- from django .db .models .signals import post_migrate
11+ from django .db .models .signals import post_migrate , pre_migrate
1212from django .utils .module_loading import module_has_submodule
1313
1414from pulpcore .exceptions .plugin import MissingPlugin
@@ -250,6 +250,7 @@ def ready(self):
250250 super ().ready ()
251251 from . import checks # noqa
252252
253+ pre_migrate .connect (_clean_app_status , sender = self , dispatch_uid = "clean_app_status" )
253254 post_migrate .connect (
254255 _ensure_default_domain , sender = self , dispatch_uid = "ensure_default_domain"
255256 )
@@ -263,6 +264,19 @@ def ready(self):
263264 )
264265
265266
267+ def _clean_app_status (sender , apps , verbosity , ** kwargs ):
268+ from django .contrib .postgres .functions import TransactionNow
269+ from django .db .models import F
270+
271+ try :
272+ AppStatus = apps .get_model ("core" , "AppStatus" )
273+ except LookupError :
274+ if verbosity >= 1 :
275+ print (_ ("AppStatus model does not exist. Skipping pre migrate cleanup." ))
276+ else :
277+ AppStatus .objects .filter (last_heartbeat__lt = TransactionNow () - F ("ttl" )).delete ()
278+
279+
266280def _populate_access_policies (sender , apps , verbosity , ** kwargs ):
267281 from pulpcore .app .util import get_view_urlpattern
268282 from pulpcore .app .viewsets import LoginViewSet
0 commit comments