feat: 静态通知同步 + 积分审计 JSONB 序列化修复
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from core.config.notification.static_sync import sync_static_notifications
|
||||
from core.config.initial.init_data import initialize_data
|
||||
from core.logging import get_logger
|
||||
|
||||
@@ -96,11 +98,70 @@ async def bootstrap() -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def run_sync_notifications(
|
||||
*,
|
||||
path: str | None = None,
|
||||
source_key: str | None = None,
|
||||
dry_run: bool = False,
|
||||
prune: bool = False,
|
||||
reconcile_targets: bool = False,
|
||||
) -> bool:
|
||||
logger.info(
|
||||
"Running static notification sync",
|
||||
path=path,
|
||||
source_key=source_key,
|
||||
dry_run=dry_run,
|
||||
prune=prune,
|
||||
reconcile_targets=reconcile_targets,
|
||||
)
|
||||
try:
|
||||
result = await sync_static_notifications(
|
||||
path=Path(path) if path is not None else None,
|
||||
source_key=source_key,
|
||||
dry_run=dry_run,
|
||||
prune=prune,
|
||||
reconcile_targets=reconcile_targets,
|
||||
)
|
||||
logger.info(
|
||||
"Static notification sync finished",
|
||||
processed=result.processed,
|
||||
created=result.created,
|
||||
updated=result.updated,
|
||||
revoked=result.revoked,
|
||||
deleted=result.deleted,
|
||||
target_links_added=result.target_links_added,
|
||||
target_links_removed=result.target_links_removed,
|
||||
dry_run=result.dry_run,
|
||||
)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("Static notification sync failed", error=str(e))
|
||||
return False
|
||||
|
||||
|
||||
def _parse_sync_notifications_args(argv: list[str]) -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="python -m core.runtime.cli sync-notifications"
|
||||
)
|
||||
parser.add_argument("--path", dest="path")
|
||||
parser.add_argument("--source-key", dest="source_key")
|
||||
parser.add_argument("--dry-run", dest="dry_run", action="store_true")
|
||||
parser.add_argument("--prune", dest="prune", action="store_true")
|
||||
parser.add_argument(
|
||||
"--reconcile-targets",
|
||||
dest="reconcile_targets",
|
||||
action="store_true",
|
||||
)
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if len(sys.argv) < 2:
|
||||
logger.error("No command provided")
|
||||
logger.info("Usage: python -m core.runtime.cli <command>")
|
||||
logger.info("Available commands: migrate, init-data, bootstrap")
|
||||
logger.info(
|
||||
"Available commands: migrate, init-data, bootstrap, sync-notifications"
|
||||
)
|
||||
return 1
|
||||
|
||||
command = sys.argv[1]
|
||||
@@ -111,9 +172,22 @@ def main() -> int:
|
||||
success = asyncio.run(run_init_data())
|
||||
elif command == "bootstrap":
|
||||
success = asyncio.run(bootstrap())
|
||||
elif command == "sync-notifications":
|
||||
args = _parse_sync_notifications_args(sys.argv[2:])
|
||||
success = asyncio.run(
|
||||
run_sync_notifications(
|
||||
path=args.path,
|
||||
source_key=args.source_key,
|
||||
dry_run=args.dry_run,
|
||||
prune=args.prune,
|
||||
reconcile_targets=args.reconcile_targets,
|
||||
)
|
||||
)
|
||||
else:
|
||||
logger.error("Unknown command", command=command)
|
||||
logger.info("Available commands: migrate, init-data, bootstrap")
|
||||
logger.info(
|
||||
"Available commands: migrate, init-data, bootstrap, sync-notifications"
|
||||
)
|
||||
return 1
|
||||
|
||||
return 0 if success else 1
|
||||
|
||||
Reference in New Issue
Block a user