Files
django-relay-controller/relaycontroller/home/tasks.py
T
2026-03-10 13:10:32 +01:00

35 lines
921 B
Python

'''
Created on 23 janv. 2026
@author: denis
'''
from celery import shared_task
from django.core.mail import EmailMultiAlternatives
from .process import MqttProcess, mqttc
@shared_task
def async_send_mail(subject, body, from_email, to=[], bcc=[], cc=[], html=None, fail_silently=False, attachments=[], connection=None):
msg = EmailMultiAlternatives(subject, body, from_email, to, bcc=bcc, cc=cc, connection=connection)
if html:
msg.attach_alternative(html, 'text/html')
for f in attachments:
msg.attach_file(f)
msg.send(fail_silently)
@shared_task(bind=True)
def start_mqtt_worker(self):
mqttc.task = MqttProcess()
mqttc.task.start()
return {"status": "success", "message": f"MQTT Worker démarré."}
@shared_task(bind=True)
def stop_mqtt_worker(self):
if mqttc.task:
mqttc.task.stop()
return {"status": "success", "message": f"MQTT Worker arrêté."}