comparison scobot/index/download_tasks.py @ 16:7a87ba2f00d9

reformat, fix some types, make more async
author drewp@bigasterisk.com
date Fri, 19 Jul 2024 00:49:38 -0700
parents 6622bacb0b84
children
comparison
equal deleted inserted replaced
15:6ed25bcaaf1f 16:7a87ba2f00d9
12 task_run_name=lambda: f'getHttp-{int(time.time())}', 12 task_run_name=lambda: f'getHttp-{int(time.time())}',
13 cache_key_fn=lambda _, args: f'getHttp-{args["url"]}', 13 cache_key_fn=lambda _, args: f'getHttp-{args["url"]}',
14 cache_expiration=datetime.timedelta(seconds=86400), 14 cache_expiration=datetime.timedelta(seconds=86400),
15 tags=['city'], # todo ratelimit based on tag 15 tags=['city'], # todo ratelimit based on tag
16 ) 16 )
17 def getCityMutableJson(url: Url): 17 async def getCityMutableJson(url: Url):
18 create_link_artifact("get", url) 18 await create_link_artifact("get", url)
19 req = httpx.get(url) # todo async 19 req = httpx.get(url) # todo async
20 req.raise_for_status() 20 req.raise_for_status()
21 return req.json() 21 return req.json()
22 22
23 23
24 @task(task_run_name=lambda: f'getHttp-{int(time.time())}', 24 @task(task_run_name=lambda: f'getHttp-{int(time.time())}',
25 cache_key_fn=lambda _, args: f'getHttp-{args["url"]}', 25 cache_key_fn=lambda _, args: f'getHttp-{args["url"]}',
26 tags=['city']) 26 tags=['city'])
27 def getCityPermanent(url: Url) -> str: 27 async def getCityPermanent(url: Url) -> str:
28 create_link_artifact("get", url) 28 await create_link_artifact("get", url)
29 req = httpx.get(url) 29 req = httpx.get(url)
30 req.raise_for_status() 30 req.raise_for_status()
31 return req.text 31 return req.text
32 32
33 33