Skip to content

Commit 2bed4b3

Browse files
committed
add todos, stubs, prototypes
1 parent 3923345 commit 2bed4b3

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

app/redis_cache.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""app.redis_cache.py"""
2+
# from walrus import Database
3+
import asyncio
4+
import functools
5+
6+
import aiocache
7+
8+
import config
9+
10+
SETTINGS = config.get_settings()
11+
12+
if SETTINGS.rediscloud_url:
13+
REDIS_URL = SETTINGS.rediscloud_url
14+
else:
15+
REDIS_URL = SETTINGS.local_redis_url
16+
17+
18+
@functools.lru_cache()
19+
def get_cache(namespace):
20+
return aiocache.Cache(
21+
aiocache.Cache.REDIS,
22+
endpoint=REDIS_URL.host,
23+
port=REDIS_URL.port,
24+
password=REDIS_URL.password,
25+
namespace=namespace,
26+
create_connection_timeout=5,
27+
)
28+
29+
30+
REDIS_CACHE = get_cache("test")
31+
32+
33+
async def cach_test():
34+
# CACHE = REDIS_DB.cache()
35+
await REDIS_CACHE.set("foo", "bar", ttl=30)
36+
print(await REDIS_CACHE.get("foo"))
37+
await REDIS_CACHE.close()
38+
39+
40+
if __name__ == "__main__":
41+
# print(REDIS_DB)
42+
# h = REDIS_DB.Hash("Test Hash")
43+
# h["foo"] = "bar"
44+
# print(h)
45+
asyncio.get_event_loop().run_until_complete(cach_test())

app/services/location/jhu.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ async def get_category(category):
5757
category = category.lower()
5858
data_id = f"jhu.{category}"
5959

60+
# TODO: check cache
61+
6062
# URL to request data from.
6163
url = BASE_URL + "time_series_covid19_%s_global.csv" % category
6264

@@ -115,6 +117,8 @@ async def get_category(category):
115117
"source": "https://github.com/ExpDev07/coronavirus-tracker-api",
116118
}
117119
LOGGER.info(f"{data_id} results:\n{pf(results, depth=1)}")
120+
# save the results to distributed cache
121+
# TODO: async
118122
return results
119123

120124

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.black]
2-
line-length = 120
2+
line-length = 100
33
target-version = ['py36', 'py37', 'py38']
44
include = '\.pyi?$'
55
exclude = '''
@@ -23,4 +23,4 @@ multi_line_output = 3
2323
include_trailing_comma = "True"
2424
force_grid_wrap = 0
2525
use_parentheses = "True"
26-
line_length = 120
26+
line_length = 100

tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def check(ctx, fmt=False, sort=False, diff=False): # pylint: disable=redefined-
4646
fmt_args.append("--diff")
4747
sort_args.append("--diff")
4848

49+
# FIXME: run each command and check return code
4950
cmd_args = []
5051
if fmt:
5152
cmd_args.extend(fmt_args)

0 commit comments

Comments
 (0)