procrastinate-org / procrastinate

PostgreSQL-based Task Queue for Python
https://procrastinate.readthedocs.io/
MIT License
852 stars 52 forks source link

Django testing documentation outdated #1099

Closed medihack closed 3 months ago

medihack commented 3 months ago

It seems that the documentation about how to test Procrastinate in Django is wrong (or outdated). For example, there is no defer method of app (app.defer("my_task", args=(1, 2))). I guess it should be something like app.configure_task("my_task", args=(1, 2)).defer(). There is also some problem when using the in_memory_app fixture as described in the documentation. When deferring a task like in_memory_app.configure_task("example_project.example_app.tasks.example_task").defer() the app still tries to use the DjangoConnector. So defer doesn't respect the InMemoryConnector, even when it is correctly set. The problem is that the Task uses the job manager of the blueprint, which is set while it is registered (so before the in_memory_app is created). We have to figure out a way for the task to respect the current_app and its job_manager or to somehow overwrite the job_manager (or the blueprint) of the task itself.

ewjoachim commented 3 months ago

Thank you for opening the issue! This doc is quite new, it was written after the (almost) full rewrite of the Django integration.

The fact that the task has a link to the job manager is necessary to do task.defer() but, as you mention, it's problematic in cases where the app change through time. I guess the only way to do it right is to rewrite tasks' job manager when switching app, ideally do it in a context manager and reset every task the way it was before when you're done (e.g. at the end of the test). I'll see if I can do something.