Skip to content

Commit f751834

Browse files
committed
Update dependencies (FastAPI, uvicorn, etc.) (ExpDev07#337)
* update `generate_reqs` invoke task for latest pipenv * fastapi 0.61 -> 0.63 * uvicorn 0.11.8 -> 0.13.4 * sentry, scout updates, etc * update requirements test * update Sources enum * linting fix (invalid-name) * use Sources enum instead of string * skip test_requirements if not python3.8
1 parent 62bc59a commit f751834

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

app/data/__init__.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@
33
from ..services.location.jhu import JhuLocationService
44
from ..services.location.nyt import NYTLocationService
55

6-
# Mapping of services to data-sources.
7-
DATA_SOURCES = {
8-
"jhu": JhuLocationService(),
9-
"csbs": CSBSLocationService(),
10-
"nyt": NYTLocationService(),
11-
}
6+
7+
class DataSourceSingleton:
8+
_instance = None
9+
10+
def __new__(self):
11+
# creates new DataSourceSingleton instance iff one does not exist.
12+
# Then returns the new/existing instance
13+
if not DataSourceSingleton._instance:
14+
DataSourceSingleton._instance = super(
15+
DataSourceSingleton, self).__new__(self)
16+
17+
# Mapping of services to data-sources.
18+
self._DATA_SOURCES = {
19+
"jhu": JhuLocationService(),
20+
"csbs": CSBSLocationService(),
21+
"nyt": NYTLocationService(),
22+
}
23+
return DataSourceSingleton._instance
1224

1325

1426
def data_source(source):
@@ -18,4 +30,6 @@ def data_source(source):
1830
:returns: The service.
1931
:rtype: LocationService
2032
"""
21-
return DATA_SOURCES.get(source.lower())
33+
34+
storedSources = DataSourceSingleton()
35+
return storedSources._DATA_SOURCES.get(source.lower())

app/routers/v2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from fastapi import APIRouter, HTTPException, Request
55

6-
from ..data import DATA_SOURCES
6+
from ..data import DataSourceSingleton
77
from ..models import LatestResponse, LocationResponse, LocationsResponse
88

99
V2 = APIRouter()
@@ -107,4 +107,5 @@ async def sources():
107107
"""
108108
Retrieves a list of data-sources that are availble to use.
109109
"""
110-
return {"sources": list(DATA_SOURCES.keys())}
110+
storedSources = DataSourceSingleton()
111+
return {"sources": list(storedSources._DATA_SOURCES.keys())}

0 commit comments

Comments
 (0)