mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-05 21:24:46 +02:00

This patch adds asynchronous task execution using a Celery backend and RabbitMQ task queue, so that the layer submission process to proceed even in the event that sending the notification email fails, and establishing an asynchronous execution mechanism that we can use in the future e.g. for triggering parse operations from the web UI. This pertains to bug 11197: https://bugzilla.yoctoproject.org/show_bug.cgi?id=11197 It updates the README to reflect the installation and configuration of a basic RabbitMQ setup, adds a 'tasks.py' file to contain task definitions, updates the 'edit_layer_view' function to send emails to administrators about new and updated layers asynchronously, modifies the 'settings.py' to include a default configuration for a RabbitMQ connection, and updates the Dockerfile to start a Celery worker alongside the Gunicorn daemon. Fixes [YOCTO #11197]. Signed-off-by: Diana Thayer <garbados@gmail.com> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
25 lines
668 B
Python
25 lines
668 B
Python
from celery import Celery
|
|
from django.core.mail import EmailMessage
|
|
from . import utils
|
|
import os
|
|
import time
|
|
|
|
try:
|
|
import settings
|
|
except ImportError:
|
|
# not in a full django env, so settings is inaccessible.
|
|
# setup django to access settings.
|
|
utils.setup_django()
|
|
import settings
|
|
|
|
tasks = Celery('layerindex',
|
|
broker=settings.RABBIT_BROKER,
|
|
backend=settings.RABBIT_BACKEND)
|
|
|
|
@tasks.task
|
|
def send_email(subject, text_content, from_email=settings.DEFAULT_FROM_EMAIL, to_emails=[]):
|
|
# We seem to need to run this within the task
|
|
utils.setup_django()
|
|
msg = EmailMessage(subject, text_content, from_email, to_emails)
|
|
msg.send()
|