@@ -220,7 +220,9 @@ def create_job_object(
220
220
env = env + [env_var_instance_name ]
221
221
222
222
# provide each pod with an environment var holding cache prefix path
223
- if "TRANSFORMER_CACHE_PREFIX" in current_app .config :
223
+ if ("TRANSFORMER_CACHE_PREFIX" in current_app .config
224
+ or "TRANSFORMER_CACHE_VPS_SITE" in current_app .config ):
225
+ TransformerManager .validate_caches ()
224
226
env += [
225
227
client .V1EnvVar (
226
228
"CACHE_PREFIX" , value = current_app .config ["TRANSFORMER_CACHE_PREFIX" ]
@@ -410,6 +412,29 @@ def persistent_volume_claim_exists(self, claim_name, namespace):
410
412
return False
411
413
return False
412
414
415
+ @staticmethod
416
+ def validate_caches ():
417
+ import time
418
+ import urllib3
419
+ if not (thissite := current_app .config .get ("TRANSFORMER_CACHE_VPS_SITE" , None )):
420
+ return
421
+
422
+ lastchecktime = current_app .config .get ("TRANSFORMER_CACHE_VPS_LASTCHECK" , 0 )
423
+ ttl = current_app .config .get ("TRANSFORMER_CACHE_VPS_INTERVAL" , 30 * 60 )
424
+ if ((now := time .time ()) - lastchecktime > ttl ):
425
+ current_app .config ["TRANSFORMER_CACHE_VPS_LASTCHECK" ] = now
426
+ vps_server = current_app .config ["TRANSFORMER_CACHE_VPS_LIVENESS_URL" ]
427
+ try :
428
+ sitedata = urllib3 .request ("GET" , vps_server ).json ()
429
+ if thissite not in sitedata :
430
+ current_app .logger .error (f"{ thissite } is not in VPS liveness data" )
431
+ servers = sorted ([_ ["address" ] for _ in sitedata [thissite ].values () if _ ["live" ]])
432
+ current_app .logger .info (f"Live xCache servers are { servers } " )
433
+ current_app .config ["TRANSFORMER_CACHE_PREFIX" ] = "," .join (servers )
434
+ except Exception as e :
435
+ current_app .logger .error (f"Exception retrieving site data: { e } " )
436
+
437
+
413
438
@staticmethod
414
439
def create_hpa_object (request_id , max_workers ):
415
440
target = client .V1CrossVersionObjectReference (
0 commit comments