trying to set up assignment of create operation

This commit is contained in:
2021-01-03 19:17:30 -06:00
parent 42a8e0c886
commit d9c30e1ef8
6 changed files with 86 additions and 17 deletions

View File

@ -22,16 +22,20 @@ class MyHTTPClient:
def make_requests_sync(self, online_hosts: List[OnlineHost], body: str) -> List(HTTPResult):
self.event_loop.run_until_complete(self.make_requests(online_hosts=online_hosts, body=body))
def post_json_sync(self, method: str, url: str, body: str) -> HTTPResult:
def post_json_sync(self, url: str, body: str, method="POST", authorization_header=None) -> HTTPResult:
self.event_loop.run_until_complete(self.post_json_sync(method=method, url=url, body=body))
async def post_json(self, method: str, url: str, body: str) -> HTTPResult:
async def post_json(self, url: str, body: str, method="POST", authorization_header=None) -> HTTPResult:
response = None
try:
headers = {}
if authorization_header != None:
headers['Authorization'] = authorization_header
response = await self.client_session.request(
method=method,
url=url,
json=body,
headers=headers,
auth=aiohttp.BasicAuth("hub", current_app.config['HUB_TOKEN']),
verify_ssl=True,
)
@ -60,7 +64,7 @@ class MyHTTPClient:
# append to tasks in the same order as online_hosts
for host in online_hosts:
tasks.append(
self.post_json(method="POST", url=host.url, body=body)
self.post_json(url=host.url, body=body)
)
# gather is like Promise.all from javascript, it returns a future which resolves to an array of results
# in the same order as the tasks that we passed in -- which were in the same order as online_hosts