Open hancush opened 3 years ago
Seems like the running events endpoint sometimes throws a 500. Guessing but not certain this happens when there are not running events. In any case, we should handle this eventuality.
Sentry issue: LA-METRO-COUNCILMATIC-53
@fatima3558 We make external requests to the sites listed in the issue description in various parts of the app. If they aren’t available, the page can’t load. That’s a pretty broad surface area for failure!
Let's start with our request to the running events endpoint in Legistar.
Can you propose a better pattern for making this request that A. sets a reasonable timeout and B. handles non-200 status codes and timeouts gracefully? I'd recommend seeing what functionality comes out of the box with the Python requests library before delving into custom code!
@hancush here's what I'm thinking about this issue so far:
A. sets a reasonable timeout -- it's quite simple to add a timeout to a get request; it's a matter of passing in a timeout
keyword (example from docs below). I'm not sure how long a reasonable timeout should be for this situation. I'm thinking about 5 seconds?
requests.get('https://github.com/', timeout=0.001)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
requests.exceptions.Timeout: HTTPConnectionPool(host='github.com', port=80): Request timed out. (timeout=0.001)
B. handles non-200 status codes and timeouts gracefully
The current logic returns an empty LAMetroEvent
queryset if the response json from granicus is empty or if none of the guids from the response json correspond to an event.
In the case of a timeout or non-200 status code, we should return the same empty queryset, but we should also add some sort of additional note about granicus being temporarily unavailable. This way, the user knows that they should try again later because there might be a meeting stream to view.
@fatima3558 In general, this makes sense to me! Yes to a 5-second timeout and great job thinking through what the method should return if the request is not successful. I agree an empty queryset is best.
we should also add some sort of additional note about granicus being temporarily unavailable. This way, the user knows that they should try again later because there might be a meeting stream to view.
These errors tend to be transient (i.e., they resolve themselves quickly), so let's table the message for now.
Can you draft a PR that adds the timeout and handling for non-200 status codes to the _streaming_meeting
property?
I added a 5-second timeout to SmartLogic requests in #771 (currently a draft).
Infrequently, the current meetings request to Legistar is reset or otherwise fails, causing the homepage to return a server error.
This is not the first issue we've had with external requests impacting the app (#543, #382). It would be a good idea to validate responses and provide fallbacks on request failures across the site. The external integrations I can think of off the top of my head are: