@@ -13,10 +13,10 @@ def _checktype(value, types, message):
1313 raise TypeError (message )
1414
1515
16- def log_event (message , retries = 10 , wait = 0.1 ):
16+ def log_event (message : str | bytes , retries = 10 , wait = 0.1 ):
1717 """
1818 Log the @message string to cloudwatch logs, using the current time.
19- message: bytes (valid utf8 required) or unicode .
19+ message: bytes (valid utf8 required) or str .
2020 retries: number of retries to make on failed socket connection
2121 wait: number of seconds to wait between retries
2222 Raises: exception if the message is too long or invalid utf8
@@ -27,7 +27,7 @@ def log_event(message, retries=10, wait=0.1):
2727 # python3 json library can't handle bytes, so preemptively decode utf-8
2828 if isinstance (message , bytes ):
2929 message = message .decode ("utf-8" )
30- _checktype (message , str , "message type must be bytes or unicode " )
30+ _checktype (message , str , "message type must be bytes or str " )
3131
3232 _checktype (retries , int , "retries must be an int" )
3333 if retries < 0 :
@@ -37,9 +37,7 @@ def log_event(message, retries=10, wait=0.1):
3737 if wait < 0 :
3838 raise ValueError ("wait must be non-negative" )
3939
40- req = {}
41- req ["message" ] = message
42- req ["timestamp" ] = int (time .time () * 1000 )
40+ req = {"message" : message , "timestamp" : int (time .time () * 1000 )}
4341 return _request (req , retries , wait )
4442
4543
@@ -62,17 +60,19 @@ async def log_event_async(message, retries=10, wait=0.1):
6260 return await _request_async (req , retries , wait )
6361
6462
63+ socket_path = "/tmp/org.globus.cwlogs"
64+
65+
6566def _connect (retries , wait ):
6667 """
6768 Try to connect to the daemon @retries + 1 times,
6869 waiting @wait seconds between tries
6970 Raise: Exception if max attempts exceeded
7071 """
71- addr = "\0 org.globus.cwlogs"
7272 for _ in range (retries + 1 ):
7373 sock = socket .socket (socket .AF_UNIX , socket .SOCK_STREAM , 0 )
7474 try :
75- sock .connect (addr )
75+ sock .connect (socket_path )
7676 except Exception as err :
7777 sock .close ()
7878 error = err
@@ -84,10 +84,10 @@ def _connect(retries, wait):
8484
8585
8686async def _connect_async (retries , wait ):
87- addr = "\0 org.globus.cwlogs"
8887 for _ in range (retries + 1 ):
88+ writer = None
8989 try :
90- reader , writer = await asyncio .open_unix_connection (path = addr )
90+ reader , writer = await asyncio .open_unix_connection (path = socket_path )
9191 except Exception as err :
9292 if writer :
9393 writer .close ()
0 commit comments