mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-07-05 20:23:17 +00:00
Create and use a decorator for background functions
This commit is contained in:
10
app/email.py
10
app/email.py
@ -1,7 +1,7 @@
|
||||
from flask import current_app, render_template
|
||||
from flask_mail import Message
|
||||
from threading import Thread
|
||||
from . import mail
|
||||
from .decorators import background
|
||||
|
||||
|
||||
def create_message(recipient, subject, template, **kwargs):
|
||||
@ -15,13 +15,7 @@ def create_message(recipient, subject, template, **kwargs):
|
||||
return msg
|
||||
|
||||
|
||||
@background
|
||||
def send(app, msg):
|
||||
with app.app_context():
|
||||
mail.send(msg)
|
||||
|
||||
|
||||
def send_async(msg):
|
||||
app = current_app._get_current_object()
|
||||
thread = Thread(target=send, args=(app, msg))
|
||||
thread.start()
|
||||
return thread
|
||||
|
Reference in New Issue
Block a user