@@ -565,12 +565,17 @@ def init_app(checks: Checks):
565565 return app
566566
567567
568- def run_check (check ):
568+ def run_check (loop , check , cache , events , force ):
569569 cprint (check .description , "white" )
570570
571- _ , success , data , _ = asyncio .run (check .run ())
572-
573- cprint (json .dumps (data , indent = 2 ), "green" if success else "red" )
571+ try :
572+ _ , success , data , _ = loop .run_until_complete (
573+ check .run (cache = cache , events = events , force = force )
574+ )
575+ cprint (json .dumps (data , indent = 2 ), "green" if success else "red" )
576+ except Exception as e :
577+ cprint (f"Error running check '{ check .project } /{ check .name } ': { e !r} " , "red" )
578+ success = False
574579 return success
575580
576581
@@ -580,6 +585,10 @@ def main(argv):
580585
581586 checks = Checks .from_conf (conf )
582587
588+ app = init_app (checks )
589+ cache = app ["telescope.cache" ]
590+ events = app ["telescope.events" ]
591+
583592 # If CLI arg is provided, run the check.
584593 if len (argv ) >= 1 and argv [0 ] == "check" :
585594 project = None
@@ -588,20 +597,21 @@ def main(argv):
588597 project = argv [1 ]
589598 if len (argv ) > 2 :
590599 name = argv [2 ]
600+ force = "--force" in argv
591601 try :
592602 selected = checks .lookup (project = project , name = name )
593603 except ValueError as e :
594604 cprint (f"{ e } in '{ config .CONFIG_FILE } '" , "red" )
595605 return 2
596606
607+ loop = asyncio .get_event_loop ()
597608 successes = []
598609 for check in selected :
599- success = run_check (check )
610+ success = run_check (loop , check , cache , events , force = force )
600611 successes .append (success )
601612
602613 return 0 if all (successes ) else 1
603614
604615 # Otherwise, run the Web app.
605- app = init_app (checks )
606616 logger .debug (f"Running at http://{ config .HOST } :{ config .PORT } " )
607617 web .run_app (app , host = config .HOST , port = config .PORT , print = False )
0 commit comments