Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes for setting / handling environment variables #206

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion basin3d/plugins/epa.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,24 @@ def _get_location_info_ogc(loc_str: str, synthesis_messages: list) -> list:
url = ('https://www.waterqualitydata.us/ogcservices/wfs/?request=GetFeature&service=wfs&version=2.0.0&typeNames=wqp_sites'
f'&SEARCHPARAMS={loc_str}%3Bproviders%3ASTORET&outputFormat=application%2Fjson')

# if the timeout limit is set via an environmental variable it will be a str. Convert it to float.
# if the conversion fails, then set value to str and get_url will throw an exception which will result
# in the get_loc_info method will fail over to the WQP Station request.
try:
geoserver_timeout_limit: Union[str, float, int] = float(EPA_GEOSERVER_WFS_TIMEOUT_LIMIT)
except ValueError as e:
msg = f'EPA_GEOSERVER_WFS_TIMEOUT_LIMIT: {e}'
logger.warning(msg)
synthesis_messages.append(msg)
geoserver_timeout_limit = EPA_GEOSERVER_WFS_TIMEOUT_LIMIT
except Exception as e:
msg = f'EPA_GEOSERVER_WFS_TIMEOUT_LIMIT: Unknown exception while trying to convert value to float: {e}'
logger.error(msg)
synthesis_messages.append(msg)
raise Exception(msg)

# ToDo: Enhancements -- stream and chunk for expected large returns, chunk site_ids into multiple calls if large list
result = get_url(url, timeout=EPA_GEOSERVER_WFS_TIMEOUT_LIMIT)
result = get_url(url, timeout=geoserver_timeout_limit)

if result and result.status_code and result.status_code == 200:
try:
Expand Down
6 changes: 3 additions & 3 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ Section 1: Data Source Configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1. You may configure BASIN-3D to source the beta version 3.0 of the Water Quality Portal Web Services API. As of this release, version 2.2 is the official version and is the default. To change to version 3.0:

$ export $EPA_WQP_API_VERSION=3.0
$ export EPA_WQP_API_VERSION=3.0

2. You may also configure an http request timeout limit for the GeoService WFS Web Service API which is the primary source for location information. If that service is unavailable within the time out limit, BASIN-3D will attempt to acquire the location information via the WQP Web Service "Station" option. The default value is 5 seconds. To set a custom time out limit in seconds:

$ export $EPA_GEOSERVER_WFS_TIMEOUT_LIMIT=1
$ export EPA_GEOSERVER_WFS_TIMEOUT_LIMIT=1

Data are publicly available and accessed via the `Water Quality Portal Web Services <https://www.waterqualitydata.us/webservices_documentation/>`_.
Please follow data usage guidelines at `User Guide <https://www.waterqualitydata.us/portal_userguide/>`_ .
Expand Down Expand Up @@ -391,7 +391,7 @@ Section 1: Data Source Configuration

5. The top-level directory path must be configured as an environmental variable in the environment where you are running basin3d::

$ export $ESSDIVE_DATASETS_PATH=<top_level_directory_path>
$ export ESSDIVE_DATASETS_PATH=<top_level_directory_path>


Section 2: Using the ESSDIVE plugin in BASIN-3D
Expand Down