I have a dash app that calls to a sql database. The database sometimes takes too long to generate the information I need. My boss has asked me to implement a two minute allowance. If the sql server decides to take longer than two minutes, I will need to put an alert that it’s busy and to try again later. I also need to make sure the callback then stops.
Here is my callback.
@app.callback(
Output('store', 'data'),
Output('error-alert', 'is_open'),
Output('graph-redirect', 'pathname'),
Input('data-button', 'n_clicks'),
State('engine-drop', 'value'),
State('start-date', 'value'),
State('region-drop', 'value'),
State('report-options', 'value'),
State('loading', 'children'),
prevent_initial_call=True,
background=True,
running=[
(Output('data-button', 'disabled'), True, False),
# (Output('loading', 'visibility'), True, False),
(Output('loading', 'children'), dls.Scale(), ''),
],
)
def query_data(n1, engine, date, region, report, loading):
if loading is None:
return dash.no_update, dash.no_update, dash.no_update
if n1:
if engine == None or region == None:
store = {}
return store, True, dash.no_update
else:
data = sqlc.get_data_for_app(region=region, engine=engine, end_date=date)
data = wr.get_past_year(df=data, end_date=date)
store = {"df": data.to_dict('records'), "date": date, "engine": engine, "report": report}
return store, False, '/graph'
return dash.no_update, dash.no_update, dash.no_update,
The line where it calls to the sql database is: data = sqlc.get_data_for_app(region=region, engine=engine, end_date=date)
I’ve attempted to use concurrent.features.ThreadPoolExecutor, but it wasn’t really working.
Any thoughts?