Add versioned metric graph authority, owned browser evidence, paginated and all-tab traversal, deterministic sampling policies, and analyst-facing run inspection. Provision the DEV/PREPROD/PROD Superset, Gitea and million-row ClickHouse lab; retain reproducible lifecycle evidence and explicit incomplete-traversal limits.
60 lines
2.9 KiB
Python
60 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
# #region FullFlow.FinanceTraversalProgress [C:3] [TYPE Module] [SEMANTICS fixture,readonly,progress,traversal]
|
|
# @BRIEF Read committed isolated PostgreSQL traversal progress without changing its run or source.
|
|
# @INVARIANT SQL is SELECT-only with validated UUID; no credential values or raw command errors are emitted.
|
|
import argparse
|
|
from datetime import UTC, datetime
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
from uuid import UUID
|
|
|
|
from release import private_environment
|
|
|
|
|
|
# #region FullFlow.FinanceTraversalProgress.Read [C:2] [TYPE Function]
|
|
# @POST Returns actual run/step/frontier counters; an absent journal is not fabricated as completed.
|
|
def read_progress(env_file, run_id):
|
|
identity = str(UUID(run_id))
|
|
query = f"""SELECT json_build_object('run_id',r.id,'status',r.status,'phase',r.phase,
|
|
'steps',(SELECT coalesce(json_agg(json_build_object('logical_step_id',s.logical_step_id,
|
|
'attempt',s.attempt,'status',s.status,'progress',s.progress)), '[]'::json)
|
|
FROM scenario_step_runs s WHERE s.run_id=r.id),
|
|
'traversals',(SELECT coalesce(json_agg(json_build_object('logical_step_id',t.logical_step_id,
|
|
'attempt',t.attempt,'status',t.status,'action',t.action,'next_ordinal',t.state->'next_ordinal',
|
|
'row_count',t.state->'row_count','source_total',t.state->'source'->'source_total',
|
|
'terminal',t.state->'terminal')), '[]'::json)
|
|
FROM scenario_traversals t WHERE t.run_id=r.id))
|
|
FROM scenario_runs r WHERE r.id='{identity}'"""
|
|
command = ['docker','compose','-p','ss-tools-full-flow','--env-file',str(env_file),
|
|
'-f','docker-compose.full-flow.yml','exec','-T','db','psql','-U','postgres','-d','ss_tools',
|
|
'-v','ON_ERROR_STOP=1','-At','-c',query]
|
|
result = subprocess.run(command,capture_output=True,text=True,timeout=30)
|
|
if result.returncode or not result.stdout.strip():
|
|
raise RuntimeError('Isolated read-only progress query failed or run absent')
|
|
return {'observed_at':datetime.now(UTC).isoformat(),**json.loads(result.stdout)}
|
|
# #endregion FullFlow.FinanceTraversalProgress.Read
|
|
|
|
|
|
# #region FullFlow.FinanceTraversalProgress.Main [C:2] [TYPE Function]
|
|
# @PRE Existing private lab env; the caller executes this read-only Docker command with authorized access.
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--env-file',type=Path,required=True)
|
|
parser.add_argument('--run-id',required=True)
|
|
parser.add_argument('--output',type=Path)
|
|
args = parser.parse_args()
|
|
private_environment(args.env_file)
|
|
value = read_progress(args.env_file,args.run_id)
|
|
text = json.dumps(value,ensure_ascii=False)
|
|
if args.output:
|
|
args.output.parent.mkdir(parents=True,exist_ok=True)
|
|
with args.output.open('a') as stream:
|
|
stream.write(text+'\n')
|
|
print(text)
|
|
# #endregion FullFlow.FinanceTraversalProgress.Main
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
# #endregion FullFlow.FinanceTraversalProgress
|