1414from mmirage .core .process .batch .registry import BatchAdapterFactory
1515
1616
17- def extract_unique_provider_batches (metadata_output_path : str ) -> List [Tuple [str , str ]]:
17+ def _normalize_metadata_paths (metadata_paths : str | Sequence [str ]) -> List [str ]:
18+ if isinstance (metadata_paths , str ):
19+ return [metadata_paths ]
20+ return [str (path ) for path in metadata_paths ]
21+
22+
23+ def _read_metadata_records (metadata_output_paths : str | Sequence [str ]) -> List [Dict [str , str ]]:
24+ records : List [Dict [str , str ]] = []
25+ for metadata_output_path in _normalize_metadata_paths (metadata_output_paths ):
26+ with open (metadata_output_path , "r" , encoding = "utf-8" ) as f :
27+ for line in f :
28+ raw = line .strip ()
29+ if not raw :
30+ continue
31+ try :
32+ record = json .loads (raw )
33+ except json .JSONDecodeError :
34+ continue
35+ if isinstance (record , dict ):
36+ records .append (record )
37+ return records
38+
39+
40+ def extract_unique_provider_batches (metadata_output_path : str | Sequence [str ]) -> List [Tuple [str , str ]]:
1841 """Parse metadata JSONL and return unique ``(provider, provider_batch_id)`` pairs.
1942
2043 Malformed lines and records missing required keys are skipped safely.
2144 """
2245 unique_pairs : List [Tuple [str , str ]] = []
2346 seen = set ()
2447
25- with open (metadata_output_path , "r" , encoding = "utf-8" ) as f :
26- for line in f :
27- raw = line .strip ()
28- if not raw :
29- continue
48+ for record in _read_metadata_records (metadata_output_path ):
49+ provider = str (record .get ("provider" , "" )).strip ().lower ()
50+ provider_batch_id = str (record .get ("provider_batch_id" , "" )).strip ()
3051
31- try :
32- record = json .loads (raw )
33- except json .JSONDecodeError :
34- continue
35-
36- provider = str (record .get ("provider" , "" )).strip ().lower ()
37- provider_batch_id = str (record .get ("provider_batch_id" , "" )).strip ()
38-
39- if not provider or not provider_batch_id :
40- continue
52+ if not provider or not provider_batch_id :
53+ continue
4154
42- pair = (provider , provider_batch_id )
43- if pair in seen :
44- continue
45- seen .add (pair )
46- unique_pairs .append (pair )
55+ pair = (provider , provider_batch_id )
56+ if pair in seen :
57+ continue
58+ seen .add (pair )
59+ unique_pairs .append (pair )
4760
4861 return unique_pairs
4962
5063
5164def run_status_checker (
52- metadata_output_path : str ,
65+ metadata_output_path : str | Sequence [ str ] ,
5366 provider_configs : Mapping [str , BatchProviderConfig ],
5467 output : TextIO = sys .stdout ,
5568) -> List [BatchSubmissionResult ]:
@@ -84,7 +97,7 @@ def run_status_checker(
8497
8598
8699def _build_provider_configs_from_metadata (
87- metadata_output_path : str ,
100+ metadata_output_path : str | Sequence [ str ] ,
88101) -> Dict [str , BatchProviderConfig ]:
89102 provider_names = {provider for provider , _ in extract_unique_provider_batches (metadata_output_path )}
90103 configs : Dict [str , BatchProviderConfig ] = {}
@@ -104,8 +117,9 @@ def _build_arg_parser() -> argparse.ArgumentParser:
104117 parser = argparse .ArgumentParser (description = "Check provider batch statuses from metadata receipts." )
105118 parser .add_argument (
106119 "--metadata-path" ,
120+ nargs = "+" ,
107121 required = True ,
108- help = "Path to metadata JSONL receipt file." ,
122+ help = "Path(s) to metadata JSONL receipt file(s). Supports multiple files ." ,
109123 )
110124 return parser
111125
0 commit comments