Skip to content

Commit 216545e

Browse files
author
Ilija Vukotic
committed
trying aiohttp
1 parent b3e48a9 commit 216545e

File tree

4 files changed

+517
-4
lines changed

4 files changed

+517
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ python = "^3.6"
99
pika = "1.1.0"
1010
make-it-sync = "^1.0.0"
1111
requests = "^2.25.0"
12+
aiohttp = "^3.8.1"
1213

1314
[tool.poetry.dev-dependencies]
1415
pytest = "^5.2"

src/servicex_did_finder_lib/communication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def add(self, file_info: Dict[str, Any]):
4444
self._summary.add_file(file_info)
4545
if self._summary.file_count == 1:
4646
self._servicex.post_transform_start()
47-
# self._servicex.put_file_add(file_info)
47+
self._servicex.put_file_add(file_info)
4848

4949
def send_on(self, count):
5050
'Send the accumulated files'

src/servicex_did_finder_lib/servicex_adaptor.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
import json
2929
from datetime import datetime
30+
3031
import requests
32+
import aiohttp
33+
3134
import logging
3235

3336

@@ -65,7 +68,7 @@ def post_status_update(self, status_msg, severity="info"):
6568
def _prefix_file(self, file_path):
6669
return file_path if not self.file_prefix else self.file_prefix+file_path
6770

68-
def put_file_add(self, file_info):
71+
async def put_file_add(self, file_info):
6972
success = False
7073
attempts = 0
7174
while not success and attempts < MAX_RETRIES:
@@ -77,10 +80,15 @@ def put_file_add(self, file_info):
7780
'file_size': file_info['file_size'],
7881
'file_events': file_info['file_events']
7982
}
80-
requests.put(self.endpoint + "/files", json=mesg)
83+
84+
async with aiohttp.ClientSession() as session:
85+
async with session.put(self.endpoint + "/files", json=mesg) as response:
86+
if response.status != 200:
87+
self.logger.error(
88+
'could not send a put_file {}'.format(response.status))
8189
self.logger.info(f"Metric: {json.dumps(mesg)}")
8290
success = True
83-
except requests.exceptions.ConnectionError:
91+
except aiohttp.ClientConnectorError:
8492
self.logger.exception(f'Connection error to ServiceX App. Will retry '
8593
f'(try {attempts} out of {MAX_RETRIES}')
8694
attempts += 1

0 commit comments

Comments
 (0)