New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Task class specialised for Django #8491
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8491 +/- ##
==========================================
+ Coverage 81.24% 81.25% +0.01%
==========================================
Files 148 149 +1
Lines 18542 18553 +11
Branches 3165 3166 +1
==========================================
+ Hits 15064 15075 +11
Misses 3191 3191
Partials 287 287
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
ab51725
to
01de765
Compare
"A common pitfall using Celery with Django is to call .delay() in a middle of a database transaction and have the task start executing before the transaction is committed. I think it's partly due to the fact that doing the call properly is a bit cumbersome." |
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
@browniebroke hey there - thanks for this contribution, I'm sure it will be very useful! Do you think it's possible to also refine the django example or add another one for the new feature? I'm positive it will increase adoption and possibly awareness of the new feature. |
Absolutely! I actually saw the example at some point during implementation and made a mental note to look at it later, but I (obviously) forgot about it 😄 Thanks for bringing it up. |
Awesome! |
I looked at the example project and it was actually not making much use of the |
yes you can go for it. use that model and use a more nice example.... |
Nice!! Perhaps this needs revisiting now that Django v5.0.1 is shipping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you plan to add anything more to this PR?
No, I don't think so. |
I will wait for other team mates opinion before merge |
I'll check with @thedrow if he's available for another review. Will do myself as well. |
this failed only after merged. it was OK during last run in the PR tox: 3.9-smoke scheduling tests via LoadScopeScheduling t/smoke/tests/test_tasks.py::test_replace::test_sanity[celery_setup_worker-celery_redis_broker-celery_redis_backend] |
I saw the error and was wondering if it was some flakyness? Seems like the smoke tasks tests worked on other python versions... 🤔 Do we know where this comes from? |
Checkout the latest run. It was indeed a hiccup. I already restarted the CI yesterday :) |
hiccup a.k.a Redis container hiccups causes Celery worker to hang -> CI reaches timeout. |
Thanks for this improvement! |
Note: Before submitting this pull request, please review our contributing
guidelines.
Description
Add a task specialised to use with Django. Offers an API to call
.delay()
on tasks at the end of the database transaction.Rationale
A common pitfall using Celery with Django is to call
.delay()
in a middle of a database transaction and have the task start executing before the transaction is committed. I think it's partly due to the fact that doing the call properly is a bit cumbersome.This PR adds a specialised task that aim at offering a nicer API for it. I've added the initial code and some docs to explain how it would be used, but before going further, I'd like to know whether this would be a welcome addition or if it's considered too out of scope.