@@ -69,9 +69,23 @@ def load_module_from_path(module_name, path_to_module):
69
69
basestring = str
70
70
71
71
try :
72
- from Pilot .proxyTools import getVO , BaseRequest , TokenBasedRequest , extract_diracx_payload
72
+ from Pilot .proxyTools import (
73
+ getVO ,
74
+ BaseRequest ,
75
+ TokenBasedRequest ,
76
+ extract_diracx_payload ,
77
+ refreshPilotToken ,
78
+ refreshUserToken
79
+ )
73
80
except ImportError :
74
- from proxyTools import getVO , BaseRequest , TokenBasedRequest , extract_diracx_payload
81
+ from proxyTools import (
82
+ getVO ,
83
+ BaseRequest ,
84
+ TokenBasedRequest ,
85
+ extract_diracx_payload ,
86
+ refreshPilotToken ,
87
+ refreshUserToken
88
+ )
75
89
76
90
try :
77
91
FileNotFoundError # pylint: disable=used-before-assignment
@@ -525,9 +539,10 @@ def __init__(
525
539
isPilotLoggerOn = True ,
526
540
pilotUUID = "unknown" ,
527
541
flushInterval = 10 ,
528
- bufsize = 1000 ,
542
+ bufsize = 250 ,
529
543
jwt = {},
530
- legacy_logging = False
544
+ legacy_logging = False ,
545
+ clientID = ""
531
546
):
532
547
"""
533
548
c'tor
@@ -538,7 +553,7 @@ def __init__(
538
553
self .url = url
539
554
self .pilotUUID = pilotUUID
540
555
self .isPilotLoggerOn = isPilotLoggerOn
541
- sendToURL = partial (sendMessage , url , pilotUUID , legacy_logging )
556
+ sendToURL = partial (sendMessage , url , pilotUUID , legacy_logging , clientID )
542
557
self .buffer = FixedSizeBuffer (sendToURL , bufsize = bufsize , autoflush = flushInterval , jwt = jwt )
543
558
544
559
def format_to_json (self , level , message ):
@@ -622,7 +637,7 @@ class FixedSizeBuffer(object):
622
637
Once it's full, a message is sent to a remote server and the buffer is renewed.
623
638
"""
624
639
625
- def __init__ (self , senderFunc , bufsize = 1000 , autoflush = 10 , jwt = {}):
640
+ def __init__ (self , senderFunc , bufsize = 250 , autoflush = 10 , jwt = {}):
626
641
"""
627
642
Constructor.
628
643
@@ -645,6 +660,10 @@ def __init__(self, senderFunc, bufsize=1000, autoflush=10, jwt={}):
645
660
self ._nlines = 0
646
661
self .senderFunc = senderFunc
647
662
self .jwt = jwt
663
+ # A fixed buffer used by a remote buffer can be deactivated:
664
+ # If there's a 403/401 error, instead of crashing the pilot,
665
+ # we will deactivate the log sending, and prefer just running the pilot.
666
+ self .activated = True
648
667
649
668
@synchronized
650
669
def write (self , content_json ):
@@ -657,13 +676,11 @@ def write(self, content_json):
657
676
:return: None
658
677
:rtype: None
659
678
"""
679
+ if not self .activated :
680
+ pass
660
681
661
682
self .output .extend (content_json )
662
-
663
- try :
664
- self ._nlines += max (1 , len (content_json ))
665
- except Exception :
666
- raise ValueError (content_json )
683
+ self ._nlines += max (1 , len (content_json ))
667
684
self .sendFullBuffer ()
668
685
669
686
@synchronized
@@ -674,7 +691,11 @@ def sendFullBuffer(self):
674
691
"""
675
692
676
693
if self ._nlines >= self .bufsize :
677
- self .flush ()
694
+ try :
695
+ self .flush ()
696
+ except Exception as e :
697
+ print ("Deactivating fixed size buffer due to" , str (e ))
698
+ self .activated = False
678
699
self .output = []
679
700
680
701
@synchronized
@@ -685,6 +706,9 @@ def flush(self, force=False):
685
706
:return: None
686
707
:rtype: None
687
708
"""
709
+ if not self .activated :
710
+ pass
711
+
688
712
if force or (self .output and self ._nlines > 0 ):
689
713
self .senderFunc (self .jwt , self .output )
690
714
self ._nlines = 0
@@ -700,7 +724,7 @@ def cancelTimer(self):
700
724
self ._timer .cancel ()
701
725
702
726
703
- def sendMessage (diracx_URL , pilotUUID , legacy = False , jwt = {}, rawMessage = []):
727
+ def sendMessage (diracx_URL , pilotUUID , legacy = False , clientID = "" , jwt = {}, rawMessage = []):
704
728
"""
705
729
Invoke a remote method on a Tornado server and pass a JSON message to it.
706
730
@@ -724,8 +748,21 @@ def sendMessage(diracx_URL, pilotUUID, legacy=False, jwt={}, rawMessage = []):
724
748
725
749
if legacy :
726
750
endpoint_path = "api/pilots/legacy/message"
751
+ refresh_callback = partial (
752
+ refreshUserToken ,
753
+ diracx_URL ,
754
+ pilotUUID ,
755
+ jwt ,
756
+ clientID
757
+ )
727
758
else :
728
759
endpoint_path = "api/pilots/internal/message"
760
+ refresh_callback = partial (
761
+ refreshPilotToken ,
762
+ diracx_URL ,
763
+ pilotUUID ,
764
+ jwt
765
+ )
729
766
730
767
config = TokenBasedRequest (
731
768
diracx_URL = diracx_URL ,
@@ -738,7 +775,8 @@ def sendMessage(diracx_URL, pilotUUID, legacy=False, jwt={}, rawMessage = []):
738
775
# Do the request
739
776
_res = config .executeRequest (
740
777
raw_data = raw_data ,
741
- json_output = False
778
+ json_output = False ,
779
+ refresh_callback = refresh_callback
742
780
)
743
781
744
782
@@ -775,7 +813,8 @@ def __init__(self, pilotParams):
775
813
flushInterval = interval ,
776
814
bufsize = bufsize ,
777
815
jwt = pilotParams .jwt ,
778
- legacy_logging = pilotParams .isLegacyLogging
816
+ legacy_logging = pilotParams .isLegacyLogging ,
817
+ clientID = pilotParams .clientID
779
818
)
780
819
781
820
self .log .isPilotLoggerOn = isPilotLoggerOn
@@ -976,7 +1015,7 @@ def __init__(self):
976
1015
self .loggerURL = None
977
1016
self .isLegacyLogging = False
978
1017
self .loggerTimerInterval = 0
979
- self .loggerBufsize = 1000
1018
+ self .loggerBufsize = 250
980
1019
self .pilotUUID = "unknown"
981
1020
self .modules = ""
982
1021
self .userEnvVariables = ""
0 commit comments