feat: Complete pipeline runner integration for API-based task launch

- Add backend/core/pipeline_runner.py with full pipeline execution logic
- Integrate main.py pipeline startup into REST API
- Add comprehensive logging and error handling
- Support mock/live/backtest modes via API

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-17 18:22:22 +08:00
parent 9ec4a8702d
commit a3f767126f
2 changed files with 389 additions and 14 deletions

View File

@@ -375,21 +375,25 @@ async def _run_pipeline(
bootstrap: Dict[str, Any],
stop_event: asyncio.Event
) -> None:
"""Background task to run the trading pipeline.
"""Background task to run the trading pipeline."""
import logging
logger = logging.getLogger(__name__)
from backend.core.pipeline_runner import run_pipeline
This is a placeholder - actual implementation will integrate with main.py
"""
try:
# TODO: Integrate with main.py pipeline execution
# This should call the actual pipeline startup logic from main.py
# For now, just wait until stop event is set
while not stop_event.is_set():
await asyncio.sleep(1)
logger.info(f"Starting pipeline for run_id: {run_id}")
await run_pipeline(
run_id=run_id,
run_dir=run_dir,
bootstrap=bootstrap,
stop_event=stop_event,
)
logger.info(f"Pipeline completed for run_id: {run_id}")
except asyncio.CancelledError:
# Handle cancellation gracefully
logger.info(f"Pipeline cancelled for run_id: {run_id}")
raise
except Exception as e:
logger.exception(f"Pipeline failed for run_id: {run_id}: {e}")
# Re-raise to allow proper cleanup
raise
finally:
# Cleanup
pass