2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828import json
2929from datetime import datetime
30+
3031import requests
32+ import aiohttp
33+
3134import 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