joeyespo / django-q-email Goto Github PK
View Code? Open in Web Editor NEWQueues the sending of email with Django Q.
License: MIT License
Queues the sending of email with Django Q.
License: MIT License
I don't think it actually needs to be added to INSTALLED_APPS. In fact, when adding it to INSTALLED_APPS I get this error:
cantor-worker_1 | Traceback (most recent call last):
cantor-worker_1 | File "manage.py", line 10, in <module>
cantor-worker_1 | execute_from_command_line(sys.argv)
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", > line 371, in execute_from_command_line
cantor-worker_1 | utility.execute()
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", > line 347, in execute
cantor-worker_1 | django.setup()
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
cantor-worker_1 | apps.populate(settings.INSTALLED_APPS)
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
cantor-worker_1 | app_config = AppConfig.create(entry)
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
cantor-worker_1 | module = import_module(entry)
cantor-worker_1 | File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
cantor-worker_1 | return _bootstrap._gcd_import(name[level:], package, level)
cantor-worker_1 | File "<frozen importlib._bootstrap>", line 994, in _gcd_import
cantor-worker_1 | File "<frozen importlib._bootstrap>", line 971, in _find_and_load
cantor-worker_1 | File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
cantor-worker_1 | File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
cantor-worker_1 | File "<frozen importlib._bootstrap_external>", line 678, in exec_module
cantor-worker_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django_q_email/__init__.py", line 1, in <module>
cantor-worker_1 | from . import backends
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django_q_email/backends.py", line 6, in <module>
cantor-worker_1 | from django_q.tasks import async_task
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django_q/tasks.py", line 12, in <module>
cantor-worker_1 | from django_q.cluster import worker, monitor
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django_q/cluster.py", line 27, in <module>
cantor-worker_1 | from django_q.models import Task, Success, Schedule
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django_q/models.py", line 15, in <module>
cantor-worker_1 | class Task(models.Model):
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 100, in __new__
cantor-worker_1 | app_config = apps.get_containing_app_config(module)
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 244, in get_containing_app_config
cantor-worker_1 | self.check_apps_ready()
cantor-worker_1 | File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 127, in check_apps_ready
cantor-worker_1 | raise AppRegistryNotReady("Apps aren't loaded yet.")
cantor-worker_1 | django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Seems like a timing issue initializing things out of order.
I get the following when running on Python 3.7:
from . import backends
File "/Users/user/.virtualenvs/project/lib/python3.7/site-packages/django_q_email/backends.py", line 9
from django_q.tasks import async as async_task
^
SyntaxError: invalid syntax
I have Django Q setup to use the DB as the queue, Q_CLUSTER = { "orm": "default" }
. With this setting, email never sends.
Using Django 3.1.1, django-q 1.3.3, django-q-email 5.0.1
In the current version of django-q, async became async_task. Thanks for your help!
OS Ubuntu22
Python 3.9.7
Django==3.2.16
django-q==1.3.9
django-q-email==5.0.1
Here is what I do
async_task(
'django_q_email.backends.send_message',
myemail,
hook='msg.hooks.send_message_done',
recipients=bloc_recipients,
group=f"block-{blocknr}",
)
It works fine but hook isn't triggered...
For info, my hook function
def send_message_done(task):
"""
hook for django_q_email.backends.send_message
"""
# args
myemail = task.args[0]
recipients = myemail.bcc
sender_email = myemail.from_email
# task elements
group = getattr(task, 'group', 'NADA')
if task.success:
msg_txt = f"{group} => {recipients}"
LOG_SUCCESS.info(msg_txt)
else:
results = result_group(group) # result_group default to failures
msg_txt = f"{group} => {recipients} | ERROR: {results}"
LOG_ERROR.error(msg_txt)
I can run some code after the call to async_task but how can I be sure it worked fine?
In addition, what could I specify in DJANGO_Q_EMAIL_ERROR_HANDLER? Setting it to 'django_q_email.backends.send_message' will do an auto-call of the method causing the Exception...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.