From b6b089f1f3f38d46b79a5798c385dbd051bed72e Mon Sep 17 00:00:00 2001 From: Joe Kaufeld Date: Fri, 24 Jun 2022 23:07:26 -0400 Subject: [PATCH 1/2] update readme with additions related to installing and settings refactor --- README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index abce973..c90e6d4 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,19 @@ backends are great candidates for community contributions. ## Basic Usage +Start by adding `django_lightweight_queue` to your `INSTALLED_APPS`: + +```python +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + ..., + "django_lightweight_queue", +] +``` + +After that, define your task in any file you want: + ```python import time from django_lightweight_queue import task @@ -67,12 +80,51 @@ present in the specified file are inherited from the global configuration. There are four built-in backends: -| Backend | Type | Description | -| -------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Synchronous | Development | Executes the task inline, without any actual queuing. | -| Redis | Production | Executes tasks at-most-once using [Redis][redis] for storage of the enqueued tasks. | -| Reliable Redis | Production | Executes tasks at-least-once using [Redis][redis] for storage of the enqueued tasks (subject to Redis consistency). Does not guarantee the task _completes_. | -| Debug Web | Debugging | Instead of running jobs it prints the url to a view that can be used to run a task in a transaction which will be rolled back. This is useful for debugging and optimising tasks. | +### Synchronous (Development backend) + +`django_lightweight_queue.backends.synchronous.SynchronousBackend` + +Executes the task inline, without any actual queuing. + +### Redis (Production backend) + +`django_lightweight_queue.backends.redis.RedisBackend` + +Executes tasks at-most-once using [Redis][redis] for storage of the enqueued tasks. + +### Reliable Redis (Production backend) + +`django_lightweight_queue.backends.reliable_redis.ReliableRedisBackend` + +Executes tasks at-least-once using [Redis][redis] for storage of the enqueued tasks (subject to Redis consistency). Does not guarantee the task _completes_. + +### Debug Web (Debug backend) + +`django_lightweight_queue.backends.debug_web.DebugWebBackend` + +Instead of running jobs it prints the url to a view that can be used to run a task in a transaction which will be rolled back. This is useful for debugging and optimising tasks. + +Use this to append the appropriate URLs to the bottom of your root `urls.py`: + +```python +from django.conf import settings +from django.urls import path, include + +urlpatterns = [ + ... +] + +if "debug_web" in settings.LIGHTWEIGHT_QUEUE_BACKEND: + from django_lightweight_queue import urls as dlq_urls + urlpatterns += [path("", include(dlq_urls))] +``` + +This backend may require an extra setting if your debug site is not on localhost: + +```python +# defaults to http://localhost:8000 +LIGHTWEIGHT_QUEUE_SITE_URL = "http://example.com:8000" +``` [redis]: https://redis.io/ From 228d665fb2db6a7605aabb87872cfd8c3bd6c5ac Mon Sep 17 00:00:00 2001 From: Joe Kaufeld Date: Sun, 26 Jun 2022 11:48:11 -0400 Subject: [PATCH 2/2] swap to formatted urlpattern direct include --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c90e6d4..83c7df8 100644 --- a/README.md +++ b/README.md @@ -114,9 +114,15 @@ urlpatterns = [ ... ] -if "debug_web" in settings.LIGHTWEIGHT_QUEUE_BACKEND: - from django_lightweight_queue import urls as dlq_urls - urlpatterns += [path("", include(dlq_urls))] +if settings.DEBUG: + urlpatterns += [ + path( + "", + include( + "django_lightweight_queue.urls", namespace="django-lightweight-queue" + ), + ) + ] ``` This backend may require an extra setting if your debug site is not on localhost: