@@ -163,6 +163,8 @@ def fake_redis_set(*args, **kwargs):
163163GOOGLE_COMP_BADGE = 'google_comp_badge'
164164API_BADGE = 'api_badge'
165165
166+ CACHED_PACKAGES = configs .PKG_LIST + configs .THIRD_PARTY_PACKAGE_LIST
167+
166168
167169def _get_pair_status_for_packages (pkg_sets ):
168170 version_and_res = {
@@ -304,19 +306,26 @@ def index():
304306@app .route ('/one_badge_image' )
305307def one_badge_image ():
306308 package_name = flask .request .args .get ('package' )
309+ force_run_check = flask .request .args .get ('force_run_check' )
307310 # Remove the last '/' from the url root
308311 url_prefix = flask .request .url_root [:- 1 ]
309312 # Call the url for each badge to run the checks. This will populate the
310313 # individual caches, which are used to calculate the final image state.
311314 # Self compatibility badge
312315 requests .get (url_prefix + flask .url_for (
313- 'self_compatibility_badge_image' , package = package_name ))
316+ 'self_compatibility_badge_image' ,
317+ package = package_name ,
318+ force_run_check = force_run_check ))
314319 # Google compatibility badge
315320 requests .get (url_prefix + flask .url_for (
316- 'google_compatibility_badge_image' , package = package_name ))
321+ 'google_compatibility_badge_image' ,
322+ package = package_name ,
323+ force_run_check = force_run_check ))
317324 # Self dependency badge
318325 requests .get (url_prefix + flask .url_for (
319- 'self_dependency_badge_image' , package = package_name ))
326+ 'self_dependency_badge_image' ,
327+ package = package_name ,
328+ force_run_check = force_run_check ))
320329
321330 status , _ , _ , _ = _get_all_results_from_cache (package_name )
322331 color = STATUS_COLOR_MAPPING [status ]
@@ -349,6 +358,7 @@ def one_badge_target():
349358def self_compatibility_badge_image ():
350359 """Badge showing whether a package is compatible with itself."""
351360 package_name = flask .request .args .get ('package' )
361+ force_run_check = flask .request .args .get ('force_run_check' )
352362
353363 version_and_res = {
354364 'py2' : {
@@ -397,7 +407,6 @@ def run_check():
397407
398408 self_comp_res = redis_client .get (
399409 '{}_self_comp_badge' .format (package_name ))
400- threading .Thread (target = run_check ).start ()
401410
402411 if self_comp_res is not None :
403412 try :
@@ -410,6 +419,13 @@ def run_check():
410419 else :
411420 details = version_and_res
412421
422+ # Run the check if there is not cached result or forced to populate the
423+ # cache or package not in cached package list.
424+ if self_comp_res is None or \
425+ force_run_check is not None or \
426+ package_name not in CACHED_PACKAGES :
427+ threading .Thread (target = run_check ).start ()
428+
413429 url = _get_badge_url (details , package_name )
414430 response = flask .make_response (requests .get (url ).text )
415431 response .content_type = SVG_CONTENT_TYPE
@@ -449,6 +465,7 @@ def self_dependency_badge_image():
449465 """Badge showing whether a package is has outdated dependencies."""
450466
451467 package_name = flask .request .args .get ('package' )
468+ force_run_check = flask .request .args .get ('force_run_check' )
452469
453470 def run_check ():
454471 res = {
@@ -485,7 +502,6 @@ def run_check():
485502
486503 dependency_res = redis_client .get (
487504 '{}_dependency_badge' .format (package_name ))
488- threading .Thread (target = run_check ).start ()
489505
490506 if dependency_res is not None :
491507 try :
@@ -498,6 +514,13 @@ def run_check():
498514 else :
499515 details = DEFAULT_DEPENDENCY_RESULT
500516
517+ # Run the check if there is not cached result or forced to populate the
518+ # cache or package not in cached package list.
519+ if dependency_res is None or \
520+ force_run_check is not None or \
521+ package_name not in CACHED_PACKAGES :
522+ threading .Thread (target = run_check ).start ()
523+
501524 url = _get_badge_url (details , package_name )
502525 response = flask .make_response (requests .get (url ).text )
503526 response .content_type = SVG_CONTENT_TYPE
@@ -525,6 +548,7 @@ def google_compatibility_badge_image():
525548 packages. If all packages success, status is SUCCESS; else set status
526549 to one of the failure types, details can be found at the target link."""
527550 package_name = flask .request .args .get ('package' )
551+ force_run_check = flask .request .args .get ('force_run_check' )
528552
529553 def run_check ():
530554 pkg_sets = [[package_name , pkg ] for pkg in configs .PKG_LIST ]
@@ -576,7 +600,6 @@ def run_check():
576600
577601 google_comp_res = redis_client .get (
578602 '{}_google_comp_badge' .format (package_name ))
579- threading .Thread (target = run_check ).start ()
580603
581604 if google_comp_res is not None :
582605 try :
@@ -586,9 +609,17 @@ def run_check():
586609 'Error occurs while converting to dict, value is {}.' .format (
587610 google_comp_res ))
588611 details = CONVERSION_ERROR_RES
612+
589613 else :
590614 details = DEFAULT_COMPATIBILITY_RESULT
591615
616+ # Run the check if there is not cached result or forced to populate the
617+ # cache or package not in cached package list.
618+ if google_comp_res is None or \
619+ force_run_check is not None or \
620+ package_name not in CACHED_PACKAGES :
621+ threading .Thread (target = run_check ).start ()
622+
592623 url = _get_badge_url (details , package_name )
593624 response = flask .make_response (requests .get (url ).text )
594625 response .content_type = SVG_CONTENT_TYPE
0 commit comments