A .NET 10 Worker Service that orchestrates job execution by polling the IAM API and executing Docker containers.
- Job Polling - Continuously polls the IAM API for pending jobs
- One-Off Jobs - Executes jobs immediately upon detection
- Scheduled Jobs - Uses cron expressions to schedule recurring jobs
- Container Execution - Executes jobs in Docker containers with parameters
- Log Streaming - Streams container logs back to the API in real-time
- Job Status Management - Updates job status (Pending → Running → Completed/Failed)
- Pause/Resume - Respects pause state for scheduled jobs
Edit appsettings.json:
{
"ApiSettings": {
"BaseUrl": "http://localhost:5000",
"PollingIntervalSeconds": 10
},
"ContainerSettings": {
"DefaultTimeout": 3600,
"DockerEndpoint": "npipe://./pipe/docker_engine"
},
"CustomerSettings": {
"CustomerName": "alpha"
}
}Set CustomerSettings:CustomerName to the specific customer this orchestrator instance should handle. If left empty, the orchestrator will process jobs for all customers.
Example configurations:
- For customer "alpha":
"CustomerName": "alpha" - For customer "bravo":
"CustomerName": "bravo" - For all customers:
"CustomerName": ""
- Windows:
npipe://./pipe/docker_engine - Linux:
unix:///var/run/docker.sock
dotnet rundocker build -t iam-orchestrator .docker run -d \
-v \\.\pipe\docker_engine:\\.\pipe\docker_engine \
-e ApiSettings__BaseUrl=http://host.docker.internal:5000 \
-e CustomerSettings__CustomerName=alpha \
iam-orchestratordocker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-e ApiSettings__BaseUrl=http://host.docker.internal:5000 \
-e CustomerSettings__CustomerName=alpha \
iam-orchestratorYou can run multiple orchestrator instances, one per customer:
# Orchestrator for customer "alpha"
docker run -d --name iam-orchestrator-alpha \
-v \\.\pipe\docker_engine:\\.\pipe\docker_engine \
-e ApiSettings__BaseUrl=http://host.docker.internal:5000 \
-e CustomerSettings__CustomerName=alpha \
iam-orchestrator
# Orchestrator for customer "bravo"
docker run -d --name iam-orchestrator-bravo \
-v \\.\pipe\docker_engine:\\.\pipe\docker_engine \
-e ApiSettings__BaseUrl=http://host.docker.internal:5000 \
-e CustomerSettings__CustomerName=bravo \
iam-orchestrator- Polling: Every 10 seconds (configurable), polls
/api/jobs/pending - Job Classification:
- One-Off Jobs: Executed immediately once
- Scheduled Jobs: Scheduled using cron expression
- Execution:
- Updates job status to
Running - Pulls Docker image if needed
- Creates and starts container with job parameters as environment variables
- Streams container logs to API
- Updates job status to
CompletedorFailed
- Updates job status to
- Scheduled Jobs:
- Monitors cron schedule
- Executes at scheduled times
- Skips execution if job is paused
The orchestrator passes these environment variables to job containers:
JOB_ID- Unique job identifierJOB_NAME- Job nameCUSTOMER- Customer nameSCRIPT_PATH- Path to the script to executeWHAT_IF- Boolean indicating dry-run mode- All job parameters as
KEY=value
0 0 * * *- Daily at midnight0 */6 * * *- Every 6 hours30 2 * * 1- Every Monday at 2:30 AM0 9 * * 1-5- Weekdays at 9:00 AM
- NCrontab - Cron expression parsing and scheduling
- Docker.DotNet - Docker API client for container management
- Microsoft.Extensions.Hosting - Background service framework