-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3074 from open-formulieren/feature/2762-request-l…
…ogging [#2762] update settings: log outgoing requests
- Loading branch information
Showing
16 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" | ||
Extensions on top of django-log-outgoing-requests | ||
TODO: move this (or parts) into the library itself, see | ||
https://github.com/maykinmedia/django-log-outgoing-requests/issues/7 | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import logging | ||
from datetime import timedelta | ||
|
||
from django.conf import settings | ||
from django.utils import timezone | ||
|
||
from celery import shared_task | ||
from log_outgoing_requests.models import OutgoingRequestsLog | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@shared_task | ||
def cleanup_request_logs() -> int: | ||
delta = timedelta(hours=settings.LOG_OUTGOING_REQUESTS_MAX_AGE) | ||
past_timestamp = timezone.now() - delta | ||
num_deleted, _ = OutgoingRequestsLog.objects.filter( | ||
timestamp__lte=past_timestamp | ||
).delete() | ||
logger.info("Deleted %d outgoing request log(s)", num_deleted) | ||
return num_deleted |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.test import TestCase, override_settings | ||
from django.utils import timezone | ||
|
||
from freezegun import freeze_time | ||
from log_outgoing_requests.models import OutgoingRequestsLog | ||
|
||
from ..tasks import cleanup_request_logs | ||
|
||
|
||
class TestLogTask(TestCase): | ||
@override_settings(LOG_OUTGOING_REQUESTS_MAX_AGE=1) # delete if >= one hour old | ||
def test_cleanup_request_logs(self): | ||
"""Assert that logs are cleaned if and only if created before specified time""" | ||
with freeze_time("2023-06-08T22:00:00Z") as frozen_time: | ||
OutgoingRequestsLog.objects.create(timestamp=timezone.now()) | ||
frozen_time.move_to("2023-06-08T23:15:00Z") | ||
to_keep = OutgoingRequestsLog.objects.create(timestamp=timezone.now()) | ||
|
||
cleanup_request_logs() | ||
|
||
self.assertQuerysetEqual( | ||
OutgoingRequestsLog.objects.all(), | ||
[to_keep.pk], | ||
transform=lambda record: record.pk, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.