-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
152 lines (133 loc) · 7.23 KB
/
app.py
File metadata and controls
152 lines (133 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from dash import Dash, dcc, html, page_container, CeleryManager, DiskcacheManager
import dash_design_kit as ddk
import plotly.express as px
import json
import os
import sys
import constants
import dash_bootstrap_components as dbc
import tasks
import diskcache
from celery import Celery
from celery.schedules import crontab
from celery.utils.log import get_task_logger
logger = get_task_logger(__name__)
celery_app = Celery(broker=os.environ.get("REDIS_URL", "redis://127.0.0.1:6379"), backend=os.environ.get("REDIS_URL", "redis://127.0.0.1:6379"))
if os.environ.get("DASH_ENTERPRISE_ENV") == "WORKSPACE":
# For testing...
# import diskcache
cache = diskcache.Cache("./cache")
background_callback_manager = DiskcacheManager(cache)
else:
# For production...
background_callback_manager = CeleryManager(celery_app)
@celery_app.task
def run_update():
tasks.load_missions()
#
# !!!!!!!!!!
# Changing to on_after_finalize from on_after_config was the trick to getting
# the update task scheduled. It was being registered, but never scheduled.
@celery_app.on_after_finalize.connect # pyright: ignore[reportOptionalMemberAccess]
def setup_periodic_tasks(sender, **kwargs):
# Update all missions once an hour at 32 minutes past
sender.add_periodic_task(
crontab(minute='32', hour='*'),
run_update.s(), # pyright: ignore[reportFunctionMemberAccess]
name='Update missions'
)
version = 'v2.1'
config_json = None
with open('config/missions.json') as missions_config:
config_json = json.load(missions_config)
if config_json is None:
print('Missions config file not found.')
sys.exit()
collections = config_json['collections']
menu = []
coloridx = 0
for collection in sorted(collections, reverse=True):
member_children = []
member = collections[collection]
item = ddk.CollapsibleMenu(title=member['title'])
missions = member['missions']
for idx, m in enumerate(sorted(missions)):
mission = missions[m]
link = constants.base + 'mission?mission_id=' + m
icolor = px.colors.qualitative.Dark24[coloridx]
coloridx = coloridx + 1
menu_item = dcc.Link(children=[ddk.Icon(icon_name='database', icon_color=icolor), mission['ui']['title']], href=link)
member_children.append(menu_item)
item.children=member_children
menu.append(item)
app = Dash(__name__, use_pages=True, suppress_callback_exceptions=True, background_callback_manager=background_callback_manager, external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server # expose server variable for Procfile
app.layout = ddk.App(show_editor=False, theme=constants.theme, children=[
dcc.Location(id='url', refresh=False),
dcc.Store(id='plots-trigger'),
dcc.Store(id='trace-trigger'),
ddk.Sidebar(
children=[
html.A(
ddk.Logo(style={'height':'80', 'padding': '14px'},
src=app.get_asset_url("logo-PMEL-lockup-light_noaaPMEL_horizontal_rgb_2024.png")
), href='https://www.pmel.noaa.gov/'
),
dcc.Link(
ddk.Title('Uncrewed Surface Vehicle Missions'),
href=constants.base
),
# This div adds a message banner under the title in the left navbar. The message shows regardless of the page being viewed. Good for shutdown banner.
# html.Div(style={"font-size":".73em", 'padding': "10px", 'margin':'5px', "border": "2px solid red"},
# children=[
# "The U.S. government is closed. This site will not be updated; however, NOAA websites and social media channels necessary to protect lives and property will be maintained. To learn more, visit ",
# dcc.Link(href="https://www.commerce.gov/news/blog", target="_blank", style={"color":"blue","text-decoration":"underline"}, children=["commerce.gov/news/blog."]),
# " For the latest forecasts and critical weather information, visit ",
# dcc.Link(href="https://weather.gov", target="_blank", style={"color":"blue","text-decoration":"underline"}, children="weather.gov.")
# ]
# ),
ddk.Menu(children=menu),
]
),
ddk.SidebarCompanion(children=[
# ddk.PageHeader(children=[
# html.Div('Parts of the US government are closed. This site will not be updated; however, NOAA websites and social media channels necessary to protect lives and property will be maintained. See ', style={'display':'inline-block'}),
# html.Div('.', style={'display':'inline-block', 'visibility': 'hidden'}),
# html.A('www.weather.gov', href='https://www.weather.gov', style={'display':'inline-block'}),
# html.Div('.', style={'display':'inline-block', 'visibility': 'hidden'}),
# html.Div(' for critical weather information. To learn more, see ', style={'display': 'inline-block'}),
# html.Div('.', style={'display':'inline-block', 'visibility': 'hidden'}),
# html.A('www.commerce.gov', href='https://www.commerce.gov', style={'display':'inline-block'}),
# html.Div('.', style={'display':'inline-block', 'visibility': 'hidden'}),
# html.Div('.', style={'display':'inline-block'})], style={'display':'inline-block'}),
page_container,
ddk.PageFooter(children=[
html.Hr(),
ddk.Block(children=[
ddk.Block(width=.3, children=[
html.Div(children=[
dcc.Link('National Oceanic and Atmospheric Administration',
href='https://www.noaa.gov/', style={'font-size': '.8em'}),
]),
html.Div(children=[
dcc.Link('Pacific Marine Environmental Laboratory',
href='https://www.pmel.noaa.gov/',style={'font-size': '.8em'}),
]),
html.Div(children=[
dcc.Link('oar.pmel.webmaster@noaa.gov', href='mailto:oar.pmel.webmaster@noaa.gov', style={'font-size': '.8em'})
]),
dcc.Link('DOC |', href='https://www.commerce.gov/', style={'font-size': '.8em'}),
dcc.Link(' NOAA |', href='https://www.noaa.gov/', style={'font-size': '.8em'}),
dcc.Link(' OAR |', href='https://www.research.noaa.gov/', style={'font-size': '.8em'}),
dcc.Link(' PMEL |', href='https://www.pmel.noaa.gov/', style={'font-size': '.8em'}),
dcc.Link(' Privacy Policy |', href='https://www.noaa.gov/disclaimer', style={'font-size': '.8em'}),
dcc.Link(' Disclaimer |', href='https://www.noaa.gov/disclaimer',style={'font-size': '.8em'}),
dcc.Link(' Accessibility', href='https://www.pmel.noaa.gov/accessibility',style={'font-size': '.8em'})
]),
ddk.Block(width=.7,children=[html.Img(src=app.get_asset_url('logo-PMEL-lockup-light_noaaPMEL_horizontal_rgb_2024.png'), style={'height': '90px', 'padding':'14px'})])
])
])
]),
])
if __name__ == '__main__':
app.run(debug=True)