goatnotify-dramatiq 0.3.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Louis Midson LAJEANTY <midsonlajeanty@proton.me>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,35 @@
1
+ Metadata-Version: 2.4
2
+ Name: goatnotify-dramatiq
3
+ Version: 0.3.0
4
+ Summary: Dramatiq queue for GoatNotify, with delivery receipts that make retries idempotent.
5
+ Keywords: notifications,email,dramatiq,queue,asyncio,typed
6
+ Author: Louis Midson LAJEANTY
7
+ Author-email: Louis Midson LAJEANTY <midsonlajeanty@proton.me>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Framework :: Django
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Typing :: Typed
16
+ Requires-Dist: goatnotify-core==0.3.0
17
+ Requires-Dist: goatnotify-django==0.3.0
18
+ Requires-Dist: dramatiq>=2.0
19
+ Requires-Dist: django>=6.1
20
+ Requires-Python: >=3.14
21
+ Project-URL: Homepage, https://github.com/goatlabshq/goatnotify
22
+ Project-URL: Documentation, https://goatlabshq.github.io/goatnotify/
23
+ Project-URL: Issues, https://github.com/goatlabshq/goatnotify/issues
24
+ Description-Content-Type: text/markdown
25
+
26
+ # goatnotify-dramatiq
27
+
28
+ Dramatiq queue for GoatNotify in Django projects. Delivery receipts make Dramatiq's retries
29
+ idempotent: a message already sent is never sent again.
30
+
31
+ ```bash
32
+ pip install goatnotify-dramatiq
33
+ ```
34
+
35
+ Documentation: <https://goatlabshq.github.io/goatnotify/queues/#dramatiq>
@@ -0,0 +1,10 @@
1
+ # goatnotify-dramatiq
2
+
3
+ Dramatiq queue for GoatNotify in Django projects. Delivery receipts make Dramatiq's retries
4
+ idempotent: a message already sent is never sent again.
5
+
6
+ ```bash
7
+ pip install goatnotify-dramatiq
8
+ ```
9
+
10
+ Documentation: <https://goatlabshq.github.io/goatnotify/queues/#dramatiq>
@@ -0,0 +1,52 @@
1
+ [project]
2
+ name = "goatnotify-dramatiq"
3
+ version = "0.3.0"
4
+ description = "Dramatiq queue for GoatNotify, with delivery receipts that make retries idempotent."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.14"
9
+ keywords = [
10
+ "notifications",
11
+ "email",
12
+ "dramatiq",
13
+ "queue",
14
+ "asyncio",
15
+ "typed",
16
+ ]
17
+ classifiers = [
18
+ "Development Status :: 3 - Alpha",
19
+ "Framework :: Django",
20
+ "Intended Audience :: Developers",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Typing :: Typed",
24
+ ]
25
+ dependencies = [
26
+ "goatnotify-core==0.3.0",
27
+ "goatnotify-django==0.3.0",
28
+ "dramatiq>=2.0",
29
+ "django>=6.1",
30
+ ]
31
+
32
+ [[project.authors]]
33
+ name = "Louis Midson LAJEANTY"
34
+ email = "midsonlajeanty@proton.me"
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/goatlabshq/goatnotify"
38
+ Documentation = "https://goatlabshq.github.io/goatnotify/"
39
+ Issues = "https://github.com/goatlabshq/goatnotify/issues"
40
+
41
+ [build-system]
42
+ requires = ["uv_build>=0.12,<0.14"]
43
+ build-backend = "uv_build"
44
+
45
+ [tool.uv.build-backend]
46
+ module-name = "goatnotify.dramatiq"
47
+
48
+ [tool.uv.sources.goatnotify-core]
49
+ workspace = true
50
+
51
+ [tool.uv.sources.goatnotify-django]
52
+ workspace = true
@@ -0,0 +1,40 @@
1
+ [project]
2
+ name = "goatnotify-dramatiq"
3
+ version = "0.3.0" # x-release-please-version
4
+ description = "Dramatiq queue for GoatNotify, with delivery receipts that make retries idempotent."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "Louis Midson LAJEANTY", email = "midsonlajeanty@proton.me" }]
9
+ requires-python = ">=3.14"
10
+ keywords = ["notifications", "email", "dramatiq", "queue", "asyncio", "typed"]
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Framework :: Django",
14
+ "Intended Audience :: Developers",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.14",
17
+ "Typing :: Typed",
18
+ ]
19
+ dependencies = [
20
+ "goatnotify-core==0.3.0", # x-release-please-version
21
+ "goatnotify-django==0.3.0", # x-release-please-version
22
+ "dramatiq>=2.0",
23
+ "django>=6.1",
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/goatlabshq/goatnotify"
28
+ Documentation = "https://goatlabshq.github.io/goatnotify/"
29
+ Issues = "https://github.com/goatlabshq/goatnotify/issues"
30
+
31
+ [build-system]
32
+ requires = ["uv_build>=0.12,<0.14"]
33
+ build-backend = "uv_build"
34
+
35
+ [tool.uv.build-backend]
36
+ module-name = "goatnotify.dramatiq"
37
+
38
+ [tool.uv.sources]
39
+ goatnotify-core = { workspace = true }
40
+ goatnotify-django = { workspace = true }
@@ -0,0 +1,3 @@
1
+ from goatnotify.dramatiq.queue import DramatiqQueue
2
+
3
+ __all__ = ["DramatiqQueue"]
@@ -0,0 +1,7 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class GoatNotifyDramatiqConfig(AppConfig):
5
+ name = "goatnotify.dramatiq"
6
+ label = "goatnotify_dramatiq"
7
+ verbose_name = "GoatNotify Dramatiq"
@@ -0,0 +1,74 @@
1
+ import asyncio
2
+ from typing import Final, Protocol, Self, cast
3
+ from uuid import uuid4
4
+
5
+ import dramatiq
6
+ from dramatiq.errors import ActorNotFound
7
+ from goatnotify.core.errors import ConfigurationError
8
+ from goatnotify.core.notification import Notifiable
9
+ from goatnotify.core.queue import NotificationJob
10
+ from goatnotify.django.serialization import dump_job
11
+
12
+ ACTOR_NAME: Final = "goatnotify.deliver"
13
+
14
+
15
+ class _Message(Protocol):
16
+ @property
17
+ def queue_name(self) -> str: ...
18
+
19
+ def copy(self, **attributes: object) -> Self: ...
20
+
21
+
22
+ class _Broker(Protocol):
23
+ def get_actor(self, actor_name: str) -> object: ...
24
+
25
+ def get_declared_queues(self) -> set[str]: ...
26
+
27
+ def declare_queue(self, queue_name: str) -> None: ...
28
+
29
+ def enqueue(self, message: _Message) -> object: ...
30
+
31
+
32
+ class _Actor(Protocol):
33
+ """The part of ``dramatiq.Actor`` used here; Dramatiq leaves its message types unknown."""
34
+
35
+ queue_name: str
36
+
37
+ def message_with_options(
38
+ self, *, args: tuple[object, ...], kwargs: dict[str, object], **options: object
39
+ ) -> _Message: ...
40
+
41
+
42
+ class DramatiqQueue:
43
+ def __init__(self, *, queue_name: str | None = None, max_retries: int | None = None) -> None:
44
+ self._queue_name = queue_name
45
+ self._options: dict[str, object] = {}
46
+ if max_retries is not None:
47
+ self._options["max_retries"] = max_retries
48
+
49
+ async def enqueue[R: Notifiable](self, job: NotificationJob[R]) -> None:
50
+ notifiable, notification = dump_job(job, queue=type(self).__name__)
51
+ broker = cast("_Broker", dramatiq.get_broker())
52
+ actor = _actor(broker)
53
+ job_id = str(uuid4())
54
+ message = actor.message_with_options(
55
+ args=(notifiable, notification, job_id), kwargs={}, **self._options
56
+ ).copy(message_id=job_id, queue_name=self._queue_name or actor.queue_name)
57
+ await asyncio.to_thread(_send, broker, message)
58
+
59
+
60
+ def _actor(broker: _Broker) -> _Actor:
61
+ try:
62
+ actor = broker.get_actor(ACTOR_NAME)
63
+ except ActorNotFound as error:
64
+ raise ConfigurationError(
65
+ f"The {ACTOR_NAME!r} actor is not registered: add 'goatnotify.dramatiq' to "
66
+ "INSTALLED_APPS so django_dramatiq discovers it"
67
+ ) from error
68
+ return cast("_Actor", actor)
69
+
70
+
71
+ def _send(broker: _Broker, message: _Message) -> None:
72
+ if message.queue_name not in broker.get_declared_queues():
73
+ broker.declare_queue(message.queue_name)
74
+ broker.enqueue(message)
@@ -0,0 +1,9 @@
1
+ import dramatiq
2
+ from goatnotify.django.delivery import deliver_sync
3
+ from goatnotify.django.serialization import Payload
4
+ from goatnotify.dramatiq.queue import ACTOR_NAME
5
+
6
+
7
+ @dramatiq.actor(actor_name=ACTOR_NAME)
8
+ def deliver_notification(notifiable: Payload, notification: Payload, job_id: str) -> None:
9
+ deliver_sync(notifiable, notification, job_id)