Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2a031df
Quick draft of auto-cleaning functionality
Archmonger Jan 31, 2024
f8b99fc
remove auto_clean from config name
Archmonger Feb 1, 2024
685db22
Add type hinting to _cached_static_contents function
Archmonger Feb 1, 2024
eba80d3
ignore_config
Archmonger Feb 1, 2024
2e089de
docs cleanup
Archmonger Feb 1, 2024
4ea41f5
CLEAN_NEEDED_BY caching
Archmonger Feb 1, 2024
836d719
fix link
Archmonger Feb 1, 2024
dbf7e12
fix tests
Archmonger Feb 1, 2024
e1bd185
minor docs wordsmithing
Archmonger Feb 1, 2024
e2c088f
Merge remote-tracking branch 'upstream/main' into robust-cleanup-config
Archmonger Feb 1, 2024
43685b8
Add management command
Archmonger Feb 1, 2024
6c1ecf0
add changelog entries
Archmonger Feb 1, 2024
ef90460
Add checks for new config values
Archmonger Feb 1, 2024
5a57807
better interface for management command
Archmonger Feb 1, 2024
75670a8
ignore settings.py attributes for management command calls
Archmonger Feb 2, 2024
3594cee
add a check for common misspelling
Archmonger Feb 2, 2024
da855dd
Add comment for a bugfix
Archmonger Feb 2, 2024
107b64c
Auto-Clean Settings docs
Archmonger Feb 2, 2024
c6b8e13
fix a few stale docs lines
Archmonger Feb 2, 2024
43ee1ac
remove dead LOC
Archmonger Feb 2, 2024
2799ed0
Django Query Postprocessor docs cleanup
Archmonger Feb 2, 2024
e8fe1da
allow REACTPY_CLEAN_INTERVAL to be None
Archmonger Feb 2, 2024
08e1025
prepare for management command docs
Archmonger Feb 3, 2024
32ceea6
management command docs
Archmonger Feb 3, 2024
3385887
minor docs styling change
Archmonger Feb 3, 2024
e0c771d
avoid django timezone module
Archmonger Feb 3, 2024
05554dc
fix tests
Archmonger Feb 3, 2024
ad62a68
fix tests in a different way
Archmonger Feb 3, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allow REACTPY_CLEAN_INTERVAL to be None
  • Loading branch information
Archmonger committed Feb 2, 2024
commit e8fe1dace06c3e2fbf6f4ede0cc4812bf28fb8f2
6 changes: 5 additions & 1 deletion docs/src/reference/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,14 @@ Use `#!python 0` to not store any session data.

**Default:** `#!python 604800`

**Example Value(s):** `#!python 0`, `#!python 3600`, `#!python 86400`
**Example Value(s):** `#!python 0`, `#!python 3600`, `#!python 86400`, `#!python None`

Minimum seconds between ReactPy automatic clean up operations.

The server will check if the interval has passed after every component disconnection, and will perform a clean if needed.

Set this value to `#!python None` to disable automatic clean up operations.

---

### `#!python REACTPY_CLEAN_SESSIONS`
Expand Down
6 changes: 3 additions & 3 deletions src/reactpy_django/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,11 @@ def reactpy_errors(app_configs, **kwargs):
)
)

if not isinstance(config.REACTPY_CLEAN_INTERVAL, int):
if not isinstance(config.REACTPY_CLEAN_INTERVAL, (int, type(None))):
errors.append(
Error(
"Invalid type for REACTPY_CLEAN_INTERVAL.",
hint="REACTPY_CLEAN_INTERVAL should be an integer.",
hint="REACTPY_CLEAN_INTERVAL should be an integer or None.",
id="reactpy_django.E023",
)
)
Expand All @@ -516,7 +516,7 @@ def reactpy_errors(app_configs, **kwargs):
errors.append(
Error(
"Invalid value for REACTPY_CLEAN_INTERVAL.",
hint="REACTPY_CLEAN_INTERVAL should be a positive integer.",
hint="REACTPY_CLEAN_INTERVAL should be a positive integer or None.",
id="reactpy_django.E024",
)
)
Expand Down
4 changes: 2 additions & 2 deletions src/reactpy_django/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ def is_clean_needed(config: Config | None = None) -> bool:

global CLEAN_NEEDED_BY

if REACTPY_CLEAN_INTERVAL == 0:
if REACTPY_CLEAN_INTERVAL is None:
return False

if CLEAN_NEEDED_BY.year == 1 or timezone.now() >= CLEAN_NEEDED_BY:
if timezone.now() >= CLEAN_NEEDED_BY:
config = config or Config.load()
CLEAN_NEEDED_BY = config.cleaned_at + timedelta(seconds=REACTPY_CLEAN_INTERVAL)

Expand Down
2 changes: 1 addition & 1 deletion src/reactpy_django/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"REACTPY_AUTO_RELOGIN",
False,
)
REACTPY_CLEAN_INTERVAL: int = getattr(
REACTPY_CLEAN_INTERVAL: int | None = getattr(
settings,
"REACTPY_CLEAN_INTERVAL",
604800, # Default to 7 days
Expand Down
2 changes: 1 addition & 1 deletion src/reactpy_django/websocket/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def disconnect(self, code: int) -> None:
)

# Queue a cleanup, if needed
if REACTPY_CLEAN_INTERVAL > -1:
if REACTPY_CLEAN_INTERVAL is not None:
try:
await database_sync_to_async(clean)()
except Exception:
Expand Down