Skip to content

Commit

Permalink
updates for tethys 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeymac committed Aug 18, 2024
1 parent ca0acc6 commit d12a379
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 95 deletions.
9 changes: 8 additions & 1 deletion install.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This file should be committed to your app code.
version: 1.0
version: 1.1
# This should be greater or equal to your tethys-platform in your environment
tethys_version: ">=4.0.0"
# This should match the app - package name in your setup.py
name: dask_tutorial

Expand All @@ -8,8 +10,13 @@ requirements:
skip: false
conda:
channels:
- conda-forge
packages:
- dask
- tethys_dask_scheduler

pip:

npm:

post:
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from setuptools import setup, find_namespace_packages
from tethys_apps.app_installation import find_resource_files
from tethys_apps.app_installation import find_all_resource_files
from tethys_apps.base.app_base import TethysAppBase

# -- Apps Definition -- #
app_package = 'dask_tutorial'
release_package = 'tethysapp-' + app_package
release_package = f'{TethysAppBase.package_namespace}-{app_package}'

# -- Python Dependencies -- #
dependencies = []

# -- Get Resource File -- #
resource_files = find_resource_files('tethysapp/' + app_package + '/templates', 'tethysapp/' + app_package)
resource_files += find_resource_files('tethysapp/' + app_package + '/public', 'tethysapp/' + app_package)
resource_files = find_all_resource_files(app_package, TethysAppBase.package_namespace)


setup(
Expand Down
2 changes: 1 addition & 1 deletion tethysapp/dask_tutorial/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Included for native namespace package support
# Included for native namespace package support
6 changes: 3 additions & 3 deletions tethysapp/dask_tutorial/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from tethys_sdk.app_settings import SchedulerSetting


class DaskTutorial(TethysAppBase):
class App(TethysAppBase):
"""
Tethys app class for Dask Tutorial.
"""
Expand All @@ -13,7 +13,7 @@ class DaskTutorial(TethysAppBase):
index = 'home'
icon = f'{package}/images/dask-logo.png'
root_url = 'dask-tutorial'
color = '#CA4D34'
color = '#c23616'
tags = ''
enable_feedback = False
feedback_emails = []
Expand All @@ -28,4 +28,4 @@ def scheduler_settings(self):
),
)

return scheduler_settings
return scheduler_settings
44 changes: 21 additions & 23 deletions tethysapp/dask_tutorial/controllers.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import random
from django.shortcuts import render, reverse, redirect
from tethys_sdk.routing import controller
from django.http.response import HttpResponseRedirect
from django.contrib import messages
from tethys_sdk.gizmos import Button
from tethys_sdk.gizmos import JobsTable
from tethys_compute.models.dask.dask_job_exception import DaskJobException
from tethysapp.dask_tutorial.app import DaskTutorial as app
from .app import App

# get job manager for the app
job_manager = app.get_job_manager()
job_manager = App.get_job_manager()


@controller
def home(request):
"""
Controller for the app home page.
"""

dask_delayed_button = Button(
display_text='Dask Delayed Job',
name='dask_delayed_button',
Expand All @@ -25,7 +25,7 @@ def home(request):
'data-bs-placement': 'top',
'title': 'Dask Delayed Job'
},
href=reverse('dask_tutorial:run_job', kwargs={'job_type': 'delayed'})
href=App.reverse('run_job', kwargs={'job_type': 'delayed'})
)

dask_distributed_button = Button(
Expand All @@ -36,7 +36,7 @@ def home(request):
'data-bs-placement': 'top',
'title': 'Dask Future Job'
},
href=reverse('dask_tutorial:run_job', kwargs={'job_type': 'distributed'})
href=App.reverse('run_job', kwargs={'job_type': 'distributed'})
)

dask_multiple_leaf_button = Button(
Expand All @@ -47,7 +47,7 @@ def home(request):
'data-bs-placement': 'top',
'title': 'Dask Multiple Leaf Jobs'
},
href=reverse('dask_tutorial:run_job', kwargs={'job_type': 'multiple-leaf'})
href=App.reverse('run_job', kwargs={'job_type': 'multiple-leaf'})
)

jobs_button = Button(
Expand All @@ -58,17 +58,17 @@ def home(request):
'data-bs-placement': 'top',
'title': 'Show All Jobs'
},
href=reverse('dask_tutorial:jobs_table')
href=App.reverse('jobs_table')
)

context = {
'dask_delayed_button': dask_delayed_button,
'dask_distributed_button': dask_distributed_button,
'dask_multiple_leaf_button': dask_multiple_leaf_button,
'jobs_button': jobs_button,
'jobs_button': jobs_button
}

return render(request, 'dask_tutorial/home.html', context)
return App.render(request, 'home.html', context)


@controller
Expand All @@ -84,8 +84,7 @@ def jobs_table(request):
striped=False,
bordered=False,
condensed=False,
actions=['logs', 'delete'],
results_url='dask_tutorial:result',
results_url=f'{App.package}:result',
refresh_interval=1000,
show_detailed_status=True,
)
Expand All @@ -98,12 +97,12 @@ def jobs_table(request):
'data-bs-placement': 'top',
'title': 'Home'
},
href=reverse('dask_tutorial:home')
href=App.reverse('home')
)

context = {'jobs_table': jobs_table_options, 'home_button': home_button}

return render(request, 'dask_tutorial/jobs_table.html', context)
return App.render(request, 'jobs_table.html', context)


@controller
Expand All @@ -123,7 +122,7 @@ def result(request, job_id):
'data-bs-placement': 'top',
'title': 'Home'
},
href=reverse('dask_tutorial:home')
href=App.reverse('home')
)

jobs_button = Button(
Expand All @@ -134,7 +133,7 @@ def result(request, job_id):
'data-bs-placement': 'top',
'title': 'Show All Jobs'
},
href=reverse('dask_tutorial:jobs_table')
href=App.reverse('jobs_table')
)

context = {
Expand All @@ -144,25 +143,24 @@ def result(request, job_id):
'jobs_button': jobs_button
}

return render(request, 'dask_tutorial/results.html', context)
return App.render(request, 'results.html', context)


@controller
def error_message(request):
messages.add_message(request, messages.ERROR, 'Invalid Scheduler!')
return redirect(reverse('dask_tutorial:home'))

return App.redirect(App.reverse('home'))

@controller
def run_job(request, job_type):
"""
Controller for the app home page.
"""
# Get scheduler from dask_primary setting.
scheduler = app.get_scheduler(name='dask_primary')
scheduler = App.get_scheduler(name='dask_primary')

if job_type.lower() == 'delayed':
from tethysapp.dask_tutorial.job_functions import delayed_job
from .job_functions import delayed_job

# Create dask delayed object
delayed = delayed_job()
Expand All @@ -183,7 +181,7 @@ def run_job(request, job_type):
try:
client = scheduler.client
except DaskJobException:
return redirect(reverse('dask_tutorial:error_message'))
return App.redirect(App.reverse('error_message'))

# Create future job instance
future = distributed_job(client)
Expand All @@ -203,7 +201,7 @@ def run_job(request, job_type):
try:
client = scheduler.client
except DaskJobException:
return redirect(reverse('dask_tutorial:error_message'))
return App.redirect(App.reverse('error_message'))

# Create future job instance
futures = multiple_leaf_job(client)
Expand All @@ -222,4 +220,4 @@ def run_job(request, job_type):
)
dask.execute(future)

return HttpResponseRedirect(reverse('dask_tutorial:jobs_table'))
return HttpResponseRedirect(App.reverse('jobs_table'))
3 changes: 0 additions & 3 deletions tethysapp/dask_tutorial/handoff.py

This file was deleted.

9 changes: 1 addition & 8 deletions tethysapp/dask_tutorial/job_functions.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import time
import dask


def inc(x):
time.sleep(3)
return x + 1


def double(x):
time.sleep(3)
return x + 2


def add(x, y):
time.sleep(10)
return x + y


def sum_up(x):
time.sleep(5)
return sum(x)
Expand All @@ -25,7 +21,6 @@ def sum_up(x):
def convert_to_dollar_sign(result):
return '$' + str(result)


# Delayed Job
def delayed_job():
output = []
Expand All @@ -36,7 +31,6 @@ def delayed_job():
output.append(c)
return dask.delayed(sum_up, pure=False)(output)


# Distributed Job
def distributed_job(client):
output = []
Expand All @@ -47,7 +41,6 @@ def distributed_job(client):
output.append(c)
return client.submit(sum_up, output)


# Multiple Leaf Distributed Job
def multiple_leaf_job(client):
output = []
Expand All @@ -56,4 +49,4 @@ def multiple_leaf_job(client):
b = client.submit(double, x, pure=False)
c = client.submit(add, a, b, pure=False)
output.append(c)
return output
return output
File renamed without changes.
8 changes: 4 additions & 4 deletions tethysapp/dask_tutorial/templates/dask_tutorial/base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "tethys_apps/app_no_nav.html" %}

{% load static %}
{% load static tethys %}

{% block title %}{{ tethys_app.name }}{% endblock %}

Expand All @@ -20,10 +20,10 @@

{% block content_dependent_styles %}
{{ block.super }}
<link href="{% static 'dask_tutorial/css/main.css' %}" rel="stylesheet"/>
<link href="{% static tethys_app|public:'css/main.css' %}" rel="stylesheet"/>
{% endblock %}

{% block scripts %}
{{ block.super }}
<script src="{% static 'dask_tutorial/js/main.js' %}" type="text/javascript"></script>
{% endblock %}
<script src="{% static tethys_app|public:'js/main.js' %}" type="text/javascript"></script>
{% endblock %}
6 changes: 3 additions & 3 deletions tethysapp/dask_tutorial/templates/dask_tutorial/error.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "dask_tutorial/base.html" %}
{% load tethys_gizmos %}
{% extends tethys_app.package|add:"/base.html" %}
{% load tethys %}

{% block app_content %}
<div class="error-message">
Expand All @@ -9,4 +9,4 @@

{% block app_actions %}
{% gizmo jobs_button %}
{% endblock %}
{% endblock %}
7 changes: 3 additions & 4 deletions tethysapp/dask_tutorial/templates/dask_tutorial/home.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "dask_tutorial/base.html" %}
{% load tethys_gizmos %}
{% extends tethys_app.package|add:"/base.html" %}
{% load tethys %}

{% block app_actions %}
{% gizmo jobs_button %}
Expand All @@ -14,5 +14,4 @@ <h2>Dask Distributed Job</h2>

<h2>Multi Leaf Distributed Job</h2>
{% gizmo dask_multiple_leaf_button %}
{% endblock %}

{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% extends "dask_tutorial/base.html" %}
{% load static tethys_gizmos %}

{% load tethys_gizmos %}
{% extends tethys_app.package|add:"/base.html" %}
{% load static tethys %}

{% block global_scripts %}
{{ block.super }}
Expand Down Expand Up @@ -34,4 +32,4 @@ <h2>Jobs Table</h2>
{% gizmo_dependencies css %}
{{ block.super }}
{% gizmo_dependencies js %}
{% endblock %}
{% endblock %}
8 changes: 3 additions & 5 deletions tethysapp/dask_tutorial/templates/dask_tutorial/results.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% extends "dask_tutorial/base.html" %}
{% load static tethys_gizmos %}

{% load tethys_gizmos %}
{% extends tethys_app.package|add:"/base.html" %}
{% load static tethys %}

{% block title %}- Gizmos - Map View{% endblock %}

Expand Down Expand Up @@ -35,4 +33,4 @@
{% gizmo_dependencies css %}
{{ block.super }}
{% gizmo_dependencies js %}
{% endblock %}
{% endblock %}
Loading

0 comments on commit d12a379

Please sign in to comment.