Skip to content

Commit

Permalink
Execute unstarted simulations, 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 5489e0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 16 additions & 1 deletion opendrift_leeway_webgui/leeway/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from celery import Celery
from django.conf import settings

from .utils import mail_to_simulation
from .models import LeewaySimulation
from .utils import mail_to_simulation, run_leeway_simulation

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "opendrift_leeway_webgui.core.settings")
app = Celery("leeway")
Expand All @@ -33,6 +34,20 @@ def setup_periodic_tasks(sender, **kwargs):
Set up periodic tasks, i.e. retrieving mails from the mailbox
"""
sender.add_periodic_task(60, check_mailbox.s(), name="check_mailbox")
sender.add_periodig_task(
60, run_unstarted_simulations.s(), name="run_unstarted_simulations"
)


@app.task
def run_unstarted_simulations():
"""
Get the next unstarted simulation and create a new simulation job
"""
next_simulation = LeewaySimulation.objects.filter(
simulation_started__isnull=True
).first()
run_leeway_simulation.apply_async([next_simulation.uuid])


@app.task
Expand Down
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 5489e0c

Please sign in to comment.