Catch errors from external service and display in alert box
Closes: #129
This commit is contained in:
parent
f19e4e4dd4
commit
7a9fbcec7b
|
@ -276,12 +276,15 @@ async def time_function(
|
||||||
func: typing.Callable[..., typing.Coroutine[typing.Any, typing.Any, typing.Any]],
|
func: typing.Callable[..., typing.Coroutine[typing.Any, typing.Any, typing.Any]],
|
||||||
*args,
|
*args,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> tuple[str, typing.Any, float]:
|
) -> tuple[str, typing.Any, float, Exception | None]:
|
||||||
"""Time the execution of an asynchronous function."""
|
"""Time the execution of an asynchronous function."""
|
||||||
start_time = time()
|
start_time, result, exception = time(), None, None
|
||||||
result = await func(*args, **kwargs)
|
try:
|
||||||
|
result = await func(*args, **kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
exception = e
|
||||||
end_time = time()
|
end_time = time()
|
||||||
return name, result, end_time - start_time
|
return name, result, end_time - start_time, exception
|
||||||
|
|
||||||
|
|
||||||
def gap_list(
|
def gap_list(
|
||||||
|
@ -344,6 +347,8 @@ async def get_data(
|
||||||
|
|
||||||
results = {call[0]: call[1] for call in result_list}
|
results = {call[0]: call[1] for call in result_list}
|
||||||
|
|
||||||
|
errors = [(call[0], call[3]) for call in result_list if call[3]]
|
||||||
|
|
||||||
gwr_advance_tickets = results["gwr_advance_tickets"]
|
gwr_advance_tickets = results["gwr_advance_tickets"]
|
||||||
|
|
||||||
data_gather_seconds = time() - t0
|
data_gather_seconds = time() - t0
|
||||||
|
@ -389,7 +394,9 @@ async def get_data(
|
||||||
events += accommodation_events
|
events += accommodation_events
|
||||||
events += travel.all_events(my_data)
|
events += travel.all_events(my_data)
|
||||||
events += conference.get_list(os.path.join(my_data, "conferences.yaml"))
|
events += conference.get_list(os.path.join(my_data, "conferences.yaml"))
|
||||||
events += results["backwell_bins"] + results["bristol_bins"]
|
for key in "backwell_bins", "bristol_bins":
|
||||||
|
if results[key]:
|
||||||
|
events += results[key]
|
||||||
events += read_events_yaml(my_data, last_year, next_year)
|
events += read_events_yaml(my_data, last_year, next_year)
|
||||||
events += subscription.get_events(os.path.join(my_data, "subscriptions.yaml"))
|
events += subscription.get_events(os.path.join(my_data, "subscriptions.yaml"))
|
||||||
events += economist.publication_dates(last_week, next_year)
|
events += economist.publication_dates(last_week, next_year)
|
||||||
|
@ -467,5 +474,6 @@ async def get_data(
|
||||||
reply["two_weeks_ago"] = two_weeks_ago
|
reply["two_weeks_ago"] = two_weeks_ago
|
||||||
|
|
||||||
reply["fullcalendar_events"] = calendar.build_events(events)
|
reply["fullcalendar_events"] = calendar.build_events(events)
|
||||||
|
reply["errors"] = errors
|
||||||
|
|
||||||
return reply
|
return reply
|
||||||
|
|
|
@ -127,6 +127,14 @@
|
||||||
Sunset: {{ sunset.strftime("%H:%M:%S") }}</li>
|
Sunset: {{ sunset.strftime("%H:%M:%S") }}</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
{% if errors %}
|
||||||
|
{% for error in errors %}
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
Error: {{ error }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<h3>Stock markets</h3>
|
<h3>Stock markets</h3>
|
||||||
{% for market in stock_markets %}
|
{% for market in stock_markets %}
|
||||||
<p>{{ market }}</p>
|
<p>{{ market }}</p>
|
||||||
|
|
Loading…
Reference in a new issue