- Added new entries to .gitignore for environment files and dynamically generated Docker Compose files. - Updated documentation to reflect the new path for the Vibe Kanban dev server script. - Enhanced task composition scripts to extract TASK_SLOT from TASK_ID, ensuring unique Orleans ports and preventing conflicts. - Removed the old vibe-dev-server script, consolidating functionality into the new structure.
4.6 KiB
API and Workers Processes
This document lists all processes that run when the API and Workers are started.
Process Hierarchy
1. API Process (dotnet run for Managing.Api)
Parent Process:
dotnet run- The .NET CLI process that starts the API- PID stored in:
.task-pids/api-${TASK_ID}.pid
- PID stored in:
Child Process:
Managing.Apiexecutable - The actual API application- Location:
src/Managing.Api/bin/Debug/net8.0/Managing.Api - This is the main ASP.NET Core application
- Location:
Background Services (within the API process):
All of these run as IHostedService within the same API process:
- GrainInitializer - Initializes Orleans grains
- DiscordService - Discord bot service
- PricesFifteenMinutesWorker - Updates prices every 15 minutes (if enabled)
- PricesOneHourWorker - Updates prices every hour (if enabled)
- PricesFourHoursWorker - Updates prices every 4 hours (if enabled)
- PricesOneDayWorker - Updates prices every day (if enabled)
- PricesFiveMinutesWorker - Updates prices every 5 minutes (if enabled)
- SpotlightWorker - Spotlight feature worker (if enabled)
- TraderWatcher - Watches traders (if enabled)
- LeaderboardWorker - Updates leaderboard (if enabled)
- FundingRatesWatcher - Watches funding rates (if enabled)
- GeneticAlgorithmWorker - Genetic algorithm worker (if enabled)
- NotifyBundleBacktestWorker - Notifies about bundle backtests (if enabled)
Orleans Components (within the API process):
- Orleans Silo - Runs on port
11111 + (TASK_SLOT - 1) * 10 - Orleans Gateway - Runs on port
30000 + (TASK_SLOT - 1) * 10 - Orleans Dashboard - Runs on port
9999 + (TASK_SLOT - 1)(development only)
2. Workers Process (dotnet run for Managing.Workers)
Parent Process:
dotnet run- The .NET CLI process that starts the Workers- PID stored in:
.task-pids/workers-${TASK_ID}.pid
- PID stored in:
Child Process:
Managing.Workersexecutable - The actual Workers application- Location:
src/Managing.Workers/bin/Debug/net8.0/Managing.Workers - This is a .NET Host application
- Location:
Background Services (within the Workers process):
All of these run as BackgroundService within the same Workers process:
- BacktestComputeWorker - Processes backtest jobs (if enabled)
- GeneticComputeWorker - Processes genetic algorithm jobs (if enabled)
- BundleBacktestHealthCheckWorker - Health check for bundle backtests (if enabled, only on TASK_SLOT=1)
Process Management
Starting Processes
Processes are started by scripts/start-api-and-workers.sh:
- API:
cd src/Managing.Api && dotnet run & - Workers:
cd src/Managing.Workers && dotnet run &
Stopping Processes
Processes are stopped by scripts/stop-task-docker.sh or the cleanup script:
- Read PID from
.task-pids/api-${TASK_ID}.pid - Kill the parent
dotnet runprocess - Kill any orphaned child processes
- Read PID from
.task-pids/workers-${TASK_ID}.pid - Kill the parent
dotnet runprocess - Kill any orphaned child processes
Finding All Related Processes
To find all processes related to a specific task:
# Find by PID file
TASK_ID="YOUR_TASK_ID"
API_PID=$(cat .task-pids/api-${TASK_ID}.pid 2>/dev/null)
WORKERS_PID=$(cat .task-pids/workers-${TASK_ID}.pid 2>/dev/null)
# Find child processes
ps -ef | grep $API_PID
ps -ef | grep $WORKERS_PID
# Find by executable name
ps aux | grep "Managing.Api"
ps aux | grep "Managing.Workers"
ps aux | grep "dotnet run"
Finding Processes by Port
# Find API process by port
lsof -i :5000 # Default API port
lsof -i :$((5000 + PORT_OFFSET)) # With port offset
# Find Orleans processes by port
lsof -i :11111 # Orleans Silo (default)
lsof -i :30000 # Orleans Gateway (default)
Important Notes
-
Single Process Architecture: All background services run within the same process as the API or Workers. They are not separate processes.
-
PID Files: The PID files store the parent
dotnet runprocess PID, not the child executable PID. -
Orphaned Processes: If the parent
dotnet runprocess is killed, the childManaging.ApiorManaging.Workersprocess may become orphaned. The cleanup script should handle this. -
Port Conflicts: Each task uses unique ports based on
PORT_OFFSET:- API:
5000 + PORT_OFFSET - PostgreSQL:
5432 + PORT_OFFSET - Redis:
6379 + PORT_OFFSET - Orleans Silo:
11111 + (TASK_SLOT - 1) * 10 - Orleans Gateway:
30000 + (TASK_SLOT - 1) * 10
- API:
-
Worker Consolidation: Most workers have been consolidated into the API process. The separate
Managing.Workersproject now only runs compute-intensive workers (BacktestComputeWorker, GeneticComputeWorker).