Skip to content

Commit

Permalink
Split sending email to server send-check-email --email {} @varmar05
Browse files Browse the repository at this point in the history
- add legacy no monkey patch
  • Loading branch information
MarcelGeo committed Dec 9, 2024
1 parent 235a421 commit 111d7f6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .prod.env
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ services:
- .prod.env
environment:
- GEVENT_WORKER=0
- NO_MONKEY_PATCH=1
volumes:
- ./server/entrypoint.sh:/app/entrypoint.sh
depends_on:
Expand All @@ -61,6 +62,7 @@ services:
- .prod.env
environment:
- GEVENT_WORKER=0
- NO_MONKEY_PATCH=1
volumes:
- ./projects:/data
- ./server/entrypoint.sh:/app/entrypoint.sh
Expand Down
72 changes: 41 additions & 31 deletions server/mergin/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']}")

Expand Down Expand Up @@ -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",
)
)

0 comments on commit 111d7f6

Please sign in to comment.