From 111d7f6f3e24149aebf6578acbca710082289873 Mon Sep 17 00:00:00 2001 From: "marcel.kocisek" Date: Mon, 9 Dec 2024 14:09:50 +0100 Subject: [PATCH] Split sending email to server send-check-email --email {} @varmar05 - add legacy no monkey patch --- .prod.env | 2 +- docker-compose.yml | 2 ++ server/mergin/commands.py | 72 ++++++++++++++++++++++----------------- 3 files changed, 44 insertions(+), 32 deletions(-) diff --git a/.prod.env b/.prod.env index e7bccfe8..8f52df39 100644 --- a/.prod.env +++ b/.prod.env @@ -193,6 +193,6 @@ GLOBAL_STORAGE=10737418240 PORT=5000 GEVENT_WORKER=True -# Deprecated from 2024.7.0 +# Deprecated from 2024.7.0, replacement is to set GEVENT_WORKER=True NO_MONKEY_PATCH=False diff --git a/docker-compose.yml b/docker-compose.yml index 1fb2bfbf..68748caa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,6 +44,7 @@ services: - .prod.env environment: - GEVENT_WORKER=0 + - NO_MONKEY_PATCH=1 volumes: - ./server/entrypoint.sh:/app/entrypoint.sh depends_on: @@ -61,6 +62,7 @@ services: - .prod.env environment: - GEVENT_WORKER=0 + - NO_MONKEY_PATCH=1 volumes: - ./projects:/data - ./server/entrypoint.sh:/app/entrypoint.sh diff --git a/server/mergin/commands.py b/server/mergin/commands.py index ab7bf04e..ac574b4c 100644 --- a/server/mergin/commands.py +++ b/server/mergin/commands.py @@ -15,11 +15,49 @@ def server(): pass @server.command() - @click.option("--email", required=False) - def check(email: str): # pylint: disable=W0612 + @click.option("--email", required=True) + def send_check_email(email: str): # pylint: disable=W0612 + """Send check email to specified email address.""" + from .celery import send_email_async + if app.config["MAIL_SUPPRESS_SEND"]: + click.echo( + click.style( + "Sending emails is disabled. Please set MAIL_SUPPRESS_SEND=False to enable sending emails.", + fg="red", + ) + ) + return + if not app.config["MAIL_DEFAULT_SENDER"]: + click.echo( + click.style( + "No default sender set. Please set MAIL_DEFAULT_SENDER environment variable", + fg="red", + ) + ) + return + email_data = { + "subject": "Mergin Maps server check", + "html": "Awesome, your email congiruration of Mergin Maps server is working.", + "recipients": [email], + "sender": app.config["MAIL_DEFAULT_SENDER"], + } + click.echo( + f"Sending email to specified email address {email}. Check your inbox." + ) + try: + send_email_async.delay(**email_data) + except Exception as e: + click.echo( + click.style( + f"Error sending email: {e}", + fg="red", + ) + ) + + @server.command() + def check(): # pylint: disable=W0612 """Check server configuration. Define email to send testing email.""" from celery import current_app - from mergin.celery import send_email click.echo(f"Mergin Maps server version: {app.config['VERSION']}") @@ -54,31 +92,3 @@ def check(email: str): # pylint: disable=W0612 ) else: click.echo("Celery running properly") - - if email: - if not app.config["MAIL_DEFAULT_SENDER"]: - click.echo( - click.style( - "No default sender set. Please set MAIL_DEFAULT_SENDER environment variable", - fg="red", - ) - ) - return - email_data = { - "subject": "Mergin Maps server check", - "html": "Awesome, your email congiruration of Mergin Maps server is working.", - "recipients": [email], - "sender": app.config["MAIL_DEFAULT_SENDER"], - } - click.echo( - f"Sending email to specified email address {email}. Check your inbox." - ) - try: - send_email(**email_data) - except Exception as e: - click.echo( - click.style( - f"Error sending email: {e}", - fg="red", - ) - )