django-qstash 0.0.10__py3-none-any.whl → 0.0.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of django-qstash might be problematic. Click here for more details.

django_qstash/__init__.py CHANGED
@@ -1,7 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.0.10"
3
+ __version__ = "0.0.11"
4
4
 
5
5
  from django_qstash.app import shared_task
6
+ from django_qstash.app import stashed_task
6
7
 
7
- __all__ = ["shared_task"]
8
+ __all__ = ["stashed_task", "shared_task"]
@@ -3,5 +3,6 @@ from __future__ import annotations
3
3
  from .base import AsyncResult
4
4
  from .base import QStashTask
5
5
  from .decorators import shared_task
6
+ from .decorators import stashed_task
6
7
 
7
- __all__ = ["AsyncResult", "QStashTask", "shared_task"]
8
+ __all__ = ["AsyncResult", "QStashTask", "stashed_task", "shared_task"]
@@ -6,24 +6,43 @@ from typing import Callable
6
6
  from django_qstash.app.base import QStashTask
7
7
 
8
8
 
9
- def shared_task(
9
+ def stashed_task(
10
10
  func: Callable | None = None,
11
11
  name: str | None = None,
12
12
  deduplicated: bool = False,
13
13
  **options: dict[str, Any],
14
14
  ) -> QStashTask:
15
15
  """
16
- Decorator that mimics Celery's shared_task
16
+ Decorator that mimics Celery's shared_task that maintains
17
+ Celery compatibility.
17
18
 
18
19
  Can be used as:
20
+
21
+ from django_qstash import shared_task
22
+
19
23
  @shared_task
20
24
  def my_task():
21
25
  pass
22
26
 
23
- @shared_task(name="custom_name", deduplicated=True)
27
+ @stashed_task(name="custom_name", deduplicated=True)
24
28
  def my_task():
25
29
  pass
26
30
  """
27
31
  if func is not None:
28
32
  return QStashTask(func, name=name, deduplicated=deduplicated, **options)
29
33
  return lambda f: QStashTask(f, name=name, deduplicated=deduplicated, **options)
34
+
35
+
36
+ def shared_task(func: Callable | None = None, **options: dict[str, Any]) -> QStashTask:
37
+ """
38
+ Decorator that is a drop-in replacement for Celery's shared_task.
39
+
40
+ Can be used as:
41
+
42
+ from django_qstash import shared_task
43
+
44
+ @shared_task
45
+ def my_task():
46
+ pass
47
+ """
48
+ return stashed_task(func, **options)
@@ -7,14 +7,14 @@ from django.apps import apps
7
7
  from django.conf import settings
8
8
  from django.utils import timezone
9
9
 
10
- from django_qstash import shared_task
10
+ from django_qstash import stashed_task
11
11
 
12
12
  DJANGO_QSTASH_RESULT_TTL = getattr(settings, "DJANGO_QSTASH_RESULT_TTL", 604800)
13
13
 
14
14
  logger = logging.getLogger(__name__)
15
15
 
16
16
 
17
- @shared_task(name="Cleanup Task Results")
17
+ @stashed_task(name="Cleanup Task Results")
18
18
  def clear_stale_results_task(
19
19
  since=None, stdout=None, user_confirm=False, *args, **options
20
20
  ):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django-qstash
3
- Version: 0.0.10
3
+ Version: 0.0.11
4
4
  Summary: A drop-in replacement for Celery's shared_task with Upstash QStash.
5
5
  Author-email: Justin Mitchel <justin@codingforentrepreneurs.com>
6
6
  Project-URL: Changelog, https://github.com/jmitchel3/django-qstash
@@ -33,16 +33,32 @@ Requires-Dist: requests>=2.30
33
33
 
34
34
  _django-qstash_ is a drop-in replacement for Celery's `shared_task`.
35
35
 
36
- To do this, we use:
36
+
37
+ ## How it works
38
+
39
+ In `tasks.py` in your apps:
40
+
41
+ ```python
42
+ from django_qstash import shared_task
43
+
44
+
45
+ @shared_task
46
+ def my_task():
47
+ pass
48
+ ```
49
+ > To use Celery too, you can use `@stashed_task` instead of `@shared_task` more below.
50
+
51
+ To do this we need:
37
52
 
38
53
  - [Upstash QStash](https://upstash.com/docs/qstash/overall/getstarted)
39
- - A single public _webhook_ to call `@shared_task` functions automatically
54
+ - A single public _webhook_ to call `@stashed_task` functions automatically
40
55
 
41
56
  This allows us to:
42
57
 
58
+ - Nearly identical usage to Celery's `@shared_task` with far less configuration and overhead
43
59
  - Focus just on Django
44
- - Drop Celery
45
- - Truly scale Django to zero
60
+ - Drop Celery completely, scale it down, or use it as normal. django-qstash can work hand-in-hand with Celery
61
+ - Unlock true serverless and scale-to-zero for Django
46
62
  - Run background tasks through webhooks
47
63
  - Cut costs
48
64
  - Trigger GitHub Actions Workflows or GitLab CI/CD pipelines for handling other kinds of background tasks based on our project's code.
@@ -51,6 +67,7 @@ This allows us to:
51
67
  ## Table of Contents
52
68
 
53
69
  - [django-qstash](#django-qstash)
70
+ - [How it works](#how-it-works)
54
71
  - [Table of Contents](#table-of-contents)
55
72
  - [Installation](#installation)
56
73
  - [Using Pip](#using-pip)
@@ -98,9 +115,9 @@ INSTALLED_APPS = [
98
115
  ##...
99
116
  ]
100
117
  ```
101
- - `django_qstash` Includes the `@shared_task` decorator and webhook view
118
+ - `django_qstash` Includes the `@shared_task` and `@stashed_task` decorators and webhook view
102
119
  - `django_qstash.results` (Optional): Store task results in Django DB
103
- - `django_qstash.schedules` (Optional): Use QStash Schedules to run your `django_qstash` tasks. Out of the box support for _django_qstash_ `@shared_task`. Schedule tasks using _cron_ (e.g. `0 0 * * *`) format which is required based on [QStash Schedules](https://upstash.com/docs/qstash/features/schedules). use [contrab.guru](https://crontab.guru/) for writing the cron format.
120
+ - `django_qstash.schedules` (Optional): Use QStash Schedules to run your `django_qstash` tasks. Out of the box support for _django_qstash_ `@stashed_task`. Schedule tasks using _cron_ (e.g. `0 0 * * *`) format which is required based on [QStash Schedules](https://upstash.com/docs/qstash/features/schedules). use [contrab.guru](https://crontab.guru/) for writing the cron format.
104
121
 
105
122
  ### Configure Webhook URL
106
123
 
@@ -144,7 +161,7 @@ There is a sample project in [sample_project/](sample_project/) that shows how a
144
161
 
145
162
  ## Usage
146
163
 
147
- Django-QStash revolves around the `shared_task` decorator. The goal is to be a drop-in replacement for Celery's `shared_task` decorator.
164
+ Django-QStash revolves around the `stashed_task` decorator. The goal is to be a drop-in replacement for Celery's `stashed_task` decorator.
148
165
 
149
166
  Here's how it works:
150
167
  - Define a Task
@@ -152,10 +169,10 @@ Here's how it works:
152
169
 
153
170
  ### Define a Task
154
171
  ```python
155
- from django_qstash import shared_task
172
+ from django_qstash import stashed_task
156
173
 
157
174
 
158
- @shared_task
175
+ @stashed_task
159
176
  def hello_world(name: str, age: int = None, activity: str = None):
160
177
  if age is None:
161
178
  print(f"Hello {name}! I see you're {activity}.")
@@ -225,10 +242,13 @@ print(json.dumps(data))
225
242
 
226
243
  ```python
227
244
  # from celery import shared_task
228
- from django_qstash import shared_task
245
+ # becomes
246
+ # from django_qstash import shared_task
247
+ # or
248
+ from django_qstash import stashed_task
229
249
 
230
250
 
231
- @shared_task
251
+ @stashed_task
232
252
  def math_add_task(a, b, save_to_file=False, *args, **kwargs):
233
253
  logger.info(f"Adding {a} and {b}")
234
254
  if save_to_file:
@@ -292,7 +312,7 @@ In Django settings, you can configure the following:
292
312
 
293
313
  ## Schedule Tasks (Optional)
294
314
 
295
- The `django_qstash.schedules` app schedules tasks using Upstash [QStash Schedules](https://upstash.com/docs/qstash/features/schedules) and the django-qstash `@shared_task` decorator.
315
+ The `django_qstash.schedules` app schedules tasks using Upstash [QStash Schedules](https://upstash.com/docs/qstash/features/schedules) and the django-qstash `@stashed_task` decorator.
296
316
 
297
317
  ### Installation
298
318
 
@@ -1,4 +1,4 @@
1
- django_qstash/__init__.py,sha256=LX7-S0Qx-tBkMzcbIy-Fv4WyLP_wY0GnNsO2YG1bJoA,129
1
+ django_qstash/__init__.py,sha256=IpryDJmo4VtbkyGvYNbMeNbhF7Cg0fvpj5d3SLT7wac,188
2
2
  django_qstash/callbacks.py,sha256=VG5tGdNzAmUEh7NlpghrxhWvnpRNXZucWmWwxaemw0M,530
3
3
  django_qstash/client.py,sha256=cgHf-g6lDAltY_Vt6GUVJNY2JSz1czBOHL-WVkkLs2M,149
4
4
  django_qstash/exceptions.py,sha256=pH6kKRJFIVFkDHUJQ9yRWmtGdBBSXpNAwMSFuNzMgPw,392
@@ -6,9 +6,9 @@ django_qstash/handlers.py,sha256=mmm8TJOqV3j1rQXooNOa128gtmALXFNCAaDZ5xwIcuw,495
6
6
  django_qstash/settings.py,sha256=YvpXMo1AdIWvbotISWJmhg0vrW3A3UQ4BieNzMfRC7Y,524
7
7
  django_qstash/utils.py,sha256=wrTU30cobO2di18BNEFtKD4ih2euf7eQNpg6p6TkQ1Y,1185
8
8
  django_qstash/views.py,sha256=H32f_jGnlwOTO0YG9znNo2b-GRYZ8TM-Wt0T62SGdXM,639
9
- django_qstash/app/__init__.py,sha256=353w1JyvIinkr3aHjyT7I01utFM56lrgIjSSfqtJkA4,187
9
+ django_qstash/app/__init__.py,sha256=kmoCVoESInzCZ_oGUiPVY4GsFQwBC07cqFJCyn9Loyk,240
10
10
  django_qstash/app/base.py,sha256=gM7GIJh_omZcxbmsrwAEadA-N6EuUJbPzh0CflOIVRg,3864
11
- django_qstash/app/decorators.py,sha256=Gn0TAxUHfS4fKUdKdArvHeWlxrRvj9_NOVnC1a6pGTQ,732
11
+ django_qstash/app/decorators.py,sha256=Zkr0dLhW5-7yGmj7JunLGcgzOwsONRyz3YkrD957DqY,1170
12
12
  django_qstash/discovery/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  django_qstash/discovery/fields.py,sha256=h-31sysbIU05KGKGBAu7uQo9bZnZg3kgjN_ZhPPMTGU,1260
14
14
  django_qstash/discovery/models.py,sha256=9ml9lTKEqEKx2uqYvejZw_BjdnowgFOPE7rYNt_8E9A,685
@@ -24,7 +24,7 @@ django_qstash/results/admin.py,sha256=q9fn3lfn0gviMfiimYij0wBCYww7FxyrOfGPr1Nvnt
24
24
  django_qstash/results/apps.py,sha256=4me4cg5yeoeSJTphkHYzGMJUfGucT47FNIUMYu5gmIo,275
25
25
  django_qstash/results/models.py,sha256=aEiAhGJOuLRtjibUw6xdQqUt3eYKLqY2as4I4QSrF5U,1047
26
26
  django_qstash/results/services.py,sha256=HvNp5D1tQ__nz4LVUTAGxuyLl_dnlBps4pJ6E9HD2kA,991
27
- django_qstash/results/tasks.py,sha256=NETuiREwCKfajWKCnnB5iAsHoSsvBIThf805_wpzjbw,2166
27
+ django_qstash/results/tasks.py,sha256=5o0Lb2XjWDVQOHPnZnW97stzdydCeq_UZzdE2j2jvEs,2168
28
28
  django_qstash/results/migrations/0001_initial.py,sha256=A90SKgWmBf4SIJYG1Jh6-b_81Ia1zIzGj3Bfl1O4-kg,1902
29
29
  django_qstash/results/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
30
  django_qstash/schedules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -40,7 +40,7 @@ django_qstash/schedules/validators.py,sha256=i8IEjnRVk-iysmqvT_kbPYpxTKCQWoX9P1J
40
40
  django_qstash/schedules/migrations/0001_initial.py,sha256=66cA8xnJV3h7QgzCaOiv-Nu3Xl9IdZQPgQKhxyW3bs4,4516
41
41
  django_qstash/schedules/migrations/0002_taskschedule_updated_at.py,sha256=6hZO0a9P2ZpOROkk7O5UXBhahghU0QfxZl4E-c3HKGw,459
42
42
  django_qstash/schedules/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
43
- django_qstash-0.0.10.dist-info/METADATA,sha256=MBBDbS-vk7yxaIa4XKKj4GHAO2xWVNIzg3s63PKoggk,15412
44
- django_qstash-0.0.10.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
45
- django_qstash-0.0.10.dist-info/top_level.txt,sha256=AlV3WSK1A0ZvKuCLsINtIJhJW8zo7SEB-D3_RAjZ0hI,14
46
- django_qstash-0.0.10.dist-info/RECORD,,
43
+ django_qstash-0.0.11.dist-info/METADATA,sha256=FoYduoYeCoobQqnx2__vsz-yXnYsysOcGRLnIfVAjxE,15971
44
+ django_qstash-0.0.11.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
45
+ django_qstash-0.0.11.dist-info/top_level.txt,sha256=AlV3WSK1A0ZvKuCLsINtIJhJW8zo7SEB-D3_RAjZ0hI,14
46
+ django_qstash-0.0.11.dist-info/RECORD,,