Repository navigation
packages/django-dramatiq-postgres: batch task purge and stagger first run - #27810
Conversation
… run The inline purge deleted expired tasks row by row, blocking consumer threads from fetching messages while it ran. Use delete_in_batches() instead. Schedule the first purge at a random point within the interval rather than on boot. Not now(), so pods that restart more often than the interval still purge.
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #27810 +/- ##
=======================================
Coverage 93.12% 93.12%
=======================================
Files 1238 1238
Lines 86901 86986 +85
Branches 4894 4894
=======================================
+ Hits 80923 81009 +86
+ Misses 5891 5890 -1
Partials 87 87
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Playwright e2eDownload this run's HTML report and traces, then open the report: gh run download 44569730060 -D playwright-artifacts
npx playwright show-report playwright-artifacts/playwright-reportInstallation instructionsInstructions for docker-composeAdd the following block to your AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-ec7b7972269bd8348563703112cc097ec11114f2
# Distroless image: AUTHENTIK_TAG=gh-ec7b7972269bd8348563703112cc097ec11114f2-distroless
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)sAfterwards, run the upgrade commands from the latest release notes. Instructions for KubernetesAdd the following block to your authentik:
outposts:
container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
image:
repository: ghcr.io/goauthentik/dev-server
tag: gh-ec7b7972269bd8348563703112cc097ec11114f2
# Distroless image: tag: gh-ec7b7972269bd8348563703112cc097ec11114f2-distrolessAfterwards, run the upgrade commands from the latest release notes. |
jsachs
left a comment
There was a problem hiding this comment.
Comments in line, I think we also might need a docs change w/r/t when the first purge happens (right after boot --> random point)
| @@ -654,19 +659,20 @@ def _purge_locks(self) -> None: | |||
| def _auto_purge(self) -> None: | |||
There was a problem hiding this comment.
Just noting that because this still runs inline from __next__, this is just going to shorten the stall rather than fully removing it. Getting the purge out of the consumer loop could be a good future TODO (when we don't need to worry about a backport).
| for task in chunked_queryset( | ||
| self.logger.info("Task purge started") | ||
| start = time.monotonic() | ||
| count = delete_in_batches( |
There was a problem hiding this comment.
Because of @receiver(pre_delete) with no sender, Django treats every model as having delete signals and can never use a plain SQL DELETE. For each batch of 1,000, Django therefore loads the Task rows plus every related TaskLog and TaskDependency into Python objects and fires pre_delete/post_delete per row.
Registering those receivers only for the models they handle (TasksModel subclasses, and Flow/FlowStageBinding/Stage) should let Django delete with plain SQL.
Maybe a good follow-up PR if we can benchmark and validate this idea.
There was a problem hiding this comment.
yeah the main reason for that is that the django @receiver doesn't support inheritance, so we'd probably end up with a custom @receiver_inheritance that binds the signals to cls and all subclasses of cls
test-migrations-from-stable runs the suite against the migrated authentik database, which already holds tasks queued at app startup. Asserting on whole tables made the test fail there.
|
Benchmarking looks good:
|
Signed-off-by: Jens Langhammer <[email protected]>
Signed-off-by: Jens Langhammer <[email protected]>
Signed-off-by: Jens Langhammer <[email protected]>
|
|
… run (cherry-pick #27810 to version-2026.8) (#27927) * Cherry-pick #27810 to version-2026.8 (with conflicts) This cherry-pick has conflicts that need manual resolution. Original PR: #27810 Original commit: e3c8395 * fix conflicts Signed-off-by: Jens Langhammer <[email protected]> --------- Signed-off-by: Jens Langhammer <[email protected]> Co-authored-by: Dewi Roberts <[email protected]> Co-authored-by: Jens Langhammer <[email protected]>
Details
Batches the worker's inline task purge with
delete_in_batches(). Deleting row by row blocked consumers from fetching messages and could stall the queue. The first purge now falls at a random point withintask_purge_intervalinstead of running on boot. It isn'tnow()because pods that restart more often than the interval would never purge.Backport to
version-2026.8, wheredelete_in_batchesalready exists via #27634.What does this PR change?
Why is this change needed?
How was this tested?
Linked issues
Checklist
make all)make docs)