import requests
from django.conf import settings
+import django.db
from django.core.management.base import BaseCommand
from emissions.models import Nonstop
asyncio.run(self.main(), debug=settings.DEBUG)
except KeyboardInterrupt:
break
- except Exception:
+ except Exception as e:
timestamp = time.time()
if (timestamp - latest_exception_timestamp) > 300:
# if latest exception was a "long" time ago, assume
latest_alert_timestamp = timestamp
alert_index += 1
+ if alert_index and isinstance(e, django.db.InterfaceError):
+ # most likely "connection already closed", because postgresql
+ # is been restarted; log then get out to be restarted.
+ logger.error('Aborting on repeated database error')
+ break
+
time.sleep(2) # retry after a bit
latest_exception_timestamp = timestamp
continue