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