Skip to content

Commit a6a21d3

Browse files
authored
Add Celery task for cleantokens (#1070)
1 parent ac20152 commit a6a21d3

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ pySilver
6666
Shaheed Haque
6767
Vinay Karanam
6868
Eduardo Oliveira
69+
Dominik George

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
### Added
2020
* #651 Batch expired token deletions in `cleartokens` management command
2121
* Added pt-BR translations.
22+
* #1070 Add a Celery task for clearing expired tokens, e.g. to be scheduled as a [periodic task](https://docs.celeryproject.org/en/stable/userguide/periodic-tasks.html)
2223

2324
### Fixed
2425
* #1012 Return status for introspecting a nonexistent token from 401 to the correct value of 200 per [RFC 7662](https://datatracker.ietf.org/doc/html/rfc7662#section-2.2).

docs/management_commands.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ To prevent the CPU and RAM high peaks during deletion process use ``CLEAR_EXPIRE
2121

2222
Note: Refresh tokens need to expire before AccessTokens can be removed from the
2323
database. Using ``cleartokens`` without ``REFRESH_TOKEN_EXPIRE_SECONDS`` has limited effect.
24+
25+
The ``cleartokens`` action can also be scheduled as a `Celery periodic task`_
26+
by using the ``clear_tokens`` task (automatically registered when using Celery).
27+
28+
.. _Celery periodic task: https://docs.celeryproject.org/en/stable/userguide/periodic-tasks.html

oauth2_provider/tasks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from celery import shared_task
2+
3+
4+
@shared_task
5+
def clear_tokens():
6+
from ...models import clear_expired # noqa
7+
8+
clear_expired()

0 commit comments

Comments
 (0)