Skip to content

Remove db_cleanup from startup #140

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

Merged
merged 4 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Using the following categories, list your changes in this order:

## [Unreleased]

### Removed

- `django-reactpy` database entries are no longer cleaned during Django application startup. Instead, it will occur on webpage loads if `REACTPY_RECONNECT_MAX` seconds has elapsed since the last cleaning.

## [3.0.0-reactpy] - 2023-03-30

### Changed
Expand Down
19 changes: 1 addition & 18 deletions src/reactpy_django/apps.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import logging

from django.apps import AppConfig
from django.db.utils import DatabaseError

from reactpy_django.utils import ComponentPreloader, db_cleanup


_logger = logging.getLogger(__name__)
from reactpy_django.utils import ComponentPreloader


class ReactPyConfig(AppConfig):
Expand All @@ -15,14 +9,3 @@ class ReactPyConfig(AppConfig):
def ready(self):
# Populate the ReactPy component registry when Django is ready
ComponentPreloader().run()

# Delete expired database entries
# Suppress exceptions to avoid issues with `manage.py` commands such as
# `test`, `migrate`, `makemigrations`, or any custom user created commands
# where the database may not be ready.
try:
db_cleanup(immediate=True)
except DatabaseError:
_logger.debug(
"Could not access ReactPy database at startup. Skipping cleanup..."
)
4 changes: 2 additions & 2 deletions tests/test_app/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

from django.core.asgi import get_asgi_application

from reactpy_django import REACTPY_WEBSOCKET_PATH


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_app.settings")

Expand All @@ -23,6 +21,8 @@
from channels.routing import ProtocolTypeRouter, URLRouter # noqa: E402
from channels.sessions import SessionMiddlewareStack # noqa: E402

from reactpy_django import REACTPY_WEBSOCKET_PATH # noqa: E402


application = ProtocolTypeRouter(
{
Expand Down