feat: move report artifacts to OSS storage
This commit is contained in:
@@ -11,7 +11,8 @@ from pathlib import Path
|
||||
from typing import Optional, Sequence, Tuple
|
||||
|
||||
from monthly_reports.contracts import ErrorCode, RESULT_SCHEMA_VERSION
|
||||
from monthly_reports.publishing import ArtifactToolBuilder, AtomicReportPublisher
|
||||
from arr_web.processing_runtime import compose_object_store
|
||||
from monthly_reports.publishing import OpenpyxlWorkbookBuilder, AtomicReportPublisher
|
||||
from monthly_reports.repository import DatabaseConfig, PostgresReportRepository, RepositoryError
|
||||
from monthly_reports.service import MonthlyReportService, RunRequest, write_run_result
|
||||
|
||||
@@ -56,14 +57,6 @@ def _parser() -> SafeArgumentParser:
|
||||
generate.add_argument("--month", required=True, help="report month in YYYY-MM")
|
||||
generate.add_argument("--as-of", required=True, help="latest included business date")
|
||||
generate.add_argument("--output-root", help="controlled output root inside the project")
|
||||
generate.add_argument(
|
||||
"--node-binary",
|
||||
help="Node.js executable; defaults to MONTHLY_REPORT_NODE_BINARY or PATH",
|
||||
)
|
||||
generate.add_argument(
|
||||
"--artifact-tool-module",
|
||||
help="absolute path to artifact_tool.mjs when package resolution is unavailable",
|
||||
)
|
||||
return parser
|
||||
|
||||
|
||||
@@ -96,23 +89,21 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
||||
output_root = PROJECT_ROOT / output_root
|
||||
output_root = output_root.resolve()
|
||||
repository = PostgresReportRepository(DatabaseConfig.from_environment())
|
||||
builder = ArtifactToolBuilder(
|
||||
PROJECT_ROOT / "monthly_reports" / "xlsx" / "build_workbook.mjs",
|
||||
node_binary=args.node_binary,
|
||||
artifact_tool_module=(
|
||||
Path(args.artifact_tool_module).expanduser()
|
||||
if args.artifact_tool_module
|
||||
else None
|
||||
),
|
||||
)
|
||||
publisher = AtomicReportPublisher(PROJECT_ROOT, output_root)
|
||||
service = MonthlyReportService(
|
||||
repository,
|
||||
builder,
|
||||
publisher,
|
||||
output_root / ".staging",
|
||||
)
|
||||
result = service.run(request)
|
||||
storage_runtime = compose_object_store()
|
||||
try:
|
||||
service = MonthlyReportService(
|
||||
repository,
|
||||
OpenpyxlWorkbookBuilder(),
|
||||
AtomicReportPublisher(
|
||||
PROJECT_ROOT,
|
||||
output_root,
|
||||
object_store=storage_runtime.object_store,
|
||||
),
|
||||
output_root / ".staging",
|
||||
)
|
||||
result = service.run(request)
|
||||
finally:
|
||||
storage_runtime.close()
|
||||
result_path = (
|
||||
output_root
|
||||
/ f"{year:04d}"
|
||||
|
||||
Reference in New Issue
Block a user