gateway/modules/workflows/methods/methodRedmine/actions/runSync.py
2026-04-21 21:30:11 +02:00

35 lines
1.2 KiB
Python

# Copyright (c) 2026 Patrick Motsch
# All rights reserved.
"""Workflow action: trigger an incremental (or full) Redmine mirror sync."""
import logging
from typing import Any, Dict
from modules.datamodels.datamodelChat import ActionResult
from modules.features.redmine.serviceRedmineSync import runSync as runMirrorSync
from ._shared import resolveInstanceContext
logger = logging.getLogger(__name__)
async def runSyncAction(self, parameters: Dict[str, Any]) -> ActionResult:
"""Pull ticket and relation updates into the local mirror.
Set ``force=True`` to ignore ``lastSyncAt`` and re-sync every issue
(expensive -- only use for initial seed or recovery).
"""
try:
user, mandateId, featureInstanceId = resolveInstanceContext(self.services, parameters)
except ValueError as exc:
return ActionResult.isFailure(error=str(exc))
force = bool(parameters.get("force") or False)
try:
result = await runMirrorSync(user, mandateId, featureInstanceId, force=force)
except Exception as exc:
logger.exception("redmine.runSync failed")
return ActionResult.isFailure(error=f"Sync failed: {exc}")
return ActionResult.isSuccess(data={"sync": result.model_dump(exclude_none=True)})