[Django] #34447: Support backgroup async repeat task. just like fastapi_utils.tasks.repeat_every

4 views
Skip to first unread message

Django

unread,
Mar 30, 2023, 2:47:38 AM3/30/23
to django-...@googlegroups.com
#34447: Support backgroup async repeat task. just like
fastapi_utils.tasks.repeat_every
----------------------------------------+------------------------
Reporter: pythonwood | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
Feature Need: **Async django should make repeat task much more easy.**

I like to use fastapi_utils.tasks.repeat_every, so easy and doc is here:
[https://fastapi-utils.davidmontague.xyz/user-guide/repeated-tasks/]

{{{
from fastapi import FastAPI
from sqlalchemy.orm import Session

from fastapi_utils.session import FastAPISessionMaker
from fastapi_utils.tasks import repeat_every

database_uri = f"sqlite:///./test.db?check_same_thread=False"
sessionmaker = FastAPISessionMaker(database_uri)

app = FastAPI()


def remove_expired_tokens(db: Session) -> None:
"""Pretend this function deletes expired tokens from the database"""


@app.on_event("startup")
@repeat_every(seconds=60 * 60) # 1 hour
def remove_expired_tokens_task() -> None:
with sessionmaker.context_session() as db:
remove_expired_tokens(db=db)
}}}


For Django, I found ''django-celery-beat and django-q and so on'', but
they are too heavy for depending a sub-system which name broker.

I hope django support this feature when running in async mode. (ASGI
Django)

--
Ticket URL: <https://code.djangoproject.com/ticket/34447>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 30, 2023, 3:17:22 AM3/30/23
to django-...@googlegroups.com
#34447: Support backgroup async repeat task. just like
fastapi_utils.tasks.repeat_every
------------------------------+--------------------------------------
Reporter: pythonwood | Owner: nobody
Type: New feature | Status: closed

Component: Core (Other) | Version: 4.1
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => wontfix


Comment:

Thanks for this ticket, however my initial response is "wontfix" as there
are 3rd-party packages that provide this. As far as I'm aware, Django
never wanted to provide background tasks.

If you don't agree, please
[https://docs.djangoproject.com/en/stable/internals/contributing/triaging-
tickets/#closing-tickets follow the triaging guidelines with regards to
wontfix tickets] and take this to DevelopersMailingList, where you'll
reach a wider audience and see what other think.

--
Ticket URL: <https://code.djangoproject.com/ticket/34447#comment:1>

Reply all
Reply to author
Forward
0 new messages