Skip to content

Commit

Permalink
Start simulations from REST API, fix #50
Browse files Browse the repository at this point in the history
  • Loading branch information
svenseeberg committed Jan 29, 2024
1 parent 297e247 commit d62f553
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 6 additions & 0 deletions opendrift_leeway_webgui/api/v1/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework import serializers

from ...leeway.models import LeewaySimulation
from ...leeway.tasks import run_leeway_simulation


class LeewaySimulationSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -33,3 +34,8 @@ class Meta:
"simulation_started",
"simulation_finished",
]

def create(self, validated_data):
simulation = LeewaySimulation.objects.create(**validated_data)
run_leeway_simulation.apply_async([simulation.uuid])
return simulation
3 changes: 0 additions & 3 deletions opendrift_leeway_webgui/leeway/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,13 @@ def send_result_mail(simulation):
"""
Create mail parts for result mail
"""
# Initialize mail
email = EmailMessage(
subject="Leeway Drift Simulation Result",
body=mail_result_text(simulation),
to=[simulation.user.email],
)
# Attach result image
if simulation.img:
email.attach_file(simulation.img.path)
# Send email
return email.send()


Expand Down

0 comments on commit d62f553

Please sign in to comment.