Skip to content

Commit cb1283c

Browse files
UN-2813 Keep only necessary changes
1 parent d7113fc commit cb1283c

60 files changed

Lines changed: 14654 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

task-backend/Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Task Backend Worker - Production Dockerfile
2+
FROM python:3.12-slim
3+
4+
# Set environment variables
5+
ENV PYTHONUNBUFFERED=1 \
6+
PYTHONDONTWRITEBYTECODE=1 \
7+
PIP_NO_CACHE_DIR=1 \
8+
PIP_DISABLE_PIP_VERSION_CHECK=1
9+
10+
# Create non-root user
11+
RUN groupadd -r taskworker && useradd -r -g taskworker taskworker
12+
13+
# Install system dependencies
14+
RUN apt-get update \
15+
&& apt-get install -y --no-install-recommends \
16+
curl \
17+
ca-certificates \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# Set working directory
21+
WORKDIR /app
22+
23+
# Copy requirements and install Python dependencies
24+
COPY requirements.txt .
25+
RUN pip install --no-cache-dir -r requirements.txt
26+
27+
# Copy task-abstraction library
28+
COPY unstract/task-abstraction/src /app/task-abstraction/src
29+
ENV PYTHONPATH="/app/task-abstraction/src:$PYTHONPATH"
30+
31+
# Copy task-backend service
32+
COPY task-backend/src /app/src
33+
COPY task-backend/pyproject.toml /app/
34+
35+
# Install task-backend in editable mode
36+
RUN pip install -e .
37+
38+
# Create directories for logs and data
39+
RUN mkdir -p /app/logs /app/data \
40+
&& chown -R taskworker:taskworker /app
41+
42+
# Switch to non-root user
43+
USER taskworker
44+
45+
# Health check
46+
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
47+
CMD python -m unstract.task_backend.cli.main --health-check
48+
49+
# Default command
50+
CMD ["python", "-m", "unstract.task_backend.cli.main"]

task-backend/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Task Backend Worker Service
2+
3+
A worker management service that uses the `unstract-task-abstraction` library to initialize and run backend-specific workers.
4+
5+
## Architecture
6+
7+
This service is **NOT an HTTP service** - it's a **worker process** that:
8+
9+
1. **Uses task-abstraction library** to get the appropriate backend client
10+
2. **Initializes backend-specific workers** (Celery, Hatchet, Temporal)
11+
3. **Registers workflows** with the selected backend
12+
4. **Runs workers** that consume tasks from the backend
13+
14+
## Backend Types
15+
16+
### Celery Workers
17+
- Connect to Redis broker
18+
- Start multiple worker processes
19+
- Consume from configured queues
20+
- Similar to existing `backend/workers/` pattern
21+
22+
### Hatchet Workers
23+
- Connect to Hatchet server via HTTP/gRPC
24+
- Register workflows with server
25+
- Poll for task assignments
26+
- Execute tasks and report results
27+
28+
### Temporal Workers
29+
- Connect to Temporal server via gRPC
30+
- Register activities and workflows
31+
- Listen for workflow executions
32+
- Handle activity execution
33+
34+
## Usage
35+
36+
```bash
37+
# Install dependencies
38+
uv sync
39+
40+
# Copy configuration
41+
cp sample.env .env
42+
# Edit .env to set TASK_BACKEND_TYPE and connection details
43+
44+
# Start worker (auto-detects backend from env)
45+
task-backend-worker
46+
47+
# Or start specific backend
48+
task-backend-worker --backend=celery
49+
task-backend-worker --backend=hatchet
50+
task-backend-worker --backend=temporal
51+
```
52+
53+
## Configuration
54+
55+
See `sample.env` for all configuration options. Key settings:
56+
57+
- `TASK_BACKEND_TYPE`: Backend to use (celery, hatchet, temporal)
58+
- `CELERY_BROKER_URL`: Redis URL for Celery
59+
- `HATCHET_CLIENT_TOKEN`: Token for Hatchet server
60+
- `TEMPORAL_HOST`: Temporal server host
61+
62+
## Integration with Platform
63+
64+
This service replaces the functionality of:
65+
- Runner Service workers
66+
- Prompt Service workers
67+
- Structure Tool workers
68+
69+
It provides the same task execution capabilities but through a unified, backend-agnostic interface using the task-abstraction library.
70+
71+
## Development
72+
73+
```bash
74+
# Run tests
75+
uv run pytest
76+
77+
# Linting
78+
uv run ruff check .
79+
uv run ruff format .
80+
81+
# Type checking
82+
uv run mypy .
83+
```

task-backend/docker-compose.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Task Backend Worker - Docker Compose for development and testing
2+
version: '3.8'
3+
4+
services:
5+
# Redis for Celery backend
6+
redis:
7+
image: redis:7-alpine
8+
ports:
9+
- "6379:6379"
10+
command: redis-server --appendonly yes
11+
volumes:
12+
- redis_data:/data
13+
healthcheck:
14+
test: ["CMD", "redis-cli", "ping"]
15+
interval: 10s
16+
timeout: 3s
17+
retries: 3
18+
19+
# Task worker with Celery backend
20+
worker-celery:
21+
build: .
22+
environment:
23+
- TASK_BACKEND_TYPE=celery
24+
- TASK_CELERY_BROKER_URL=redis://redis:6379/0
25+
- TASK_CELERY_RESULT_BACKEND=redis://redis:6379/0
26+
- TASK_WORKER_NAME=celery-worker-1
27+
- TASK_WORKER_CONCURRENCY=4
28+
- TASK_LOG_LEVEL=INFO
29+
depends_on:
30+
redis:
31+
condition: service_healthy
32+
volumes:
33+
- ./logs:/app/logs
34+
restart: unless-stopped
35+
36+
# Task worker with Hatchet backend (requires external Hatchet server)
37+
worker-hatchet:
38+
build: .
39+
environment:
40+
- TASK_BACKEND_TYPE=hatchet
41+
- TASK_HATCHET_TOKEN=${HATCHET_TOKEN}
42+
- TASK_HATCHET_SERVER_URL=${HATCHET_SERVER_URL:-https://app.hatchet.run}
43+
- TASK_WORKER_NAME=hatchet-worker-1
44+
- TASK_LOG_LEVEL=INFO
45+
volumes:
46+
- ./logs:/app/logs
47+
restart: unless-stopped
48+
profiles:
49+
- hatchet
50+
51+
# Temporal server for development
52+
temporal:
53+
image: temporalio/auto-setup:1.22
54+
ports:
55+
- "7233:7233"
56+
- "8080:8080" # Web UI
57+
environment:
58+
- DB=postgresql
59+
- DB_PORT=5432
60+
- POSTGRES_USER=temporal
61+
- POSTGRES_PWD=temporal
62+
- POSTGRES_SEEDS=postgres
63+
depends_on:
64+
postgres:
65+
condition: service_healthy
66+
volumes:
67+
- temporal_data:/etc/temporal
68+
profiles:
69+
- temporal
70+
71+
# PostgreSQL for Temporal
72+
postgres:
73+
image: postgres:15-alpine
74+
environment:
75+
- POSTGRES_USER=temporal
76+
- POSTGRES_PASSWORD=temporal
77+
- POSTGRES_DB=temporal
78+
ports:
79+
- "5432:5432"
80+
volumes:
81+
- postgres_data:/var/lib/postgresql/data
82+
healthcheck:
83+
test: ["CMD-SHELL", "pg_isready -U temporal"]
84+
interval: 10s
85+
timeout: 5s
86+
retries: 5
87+
profiles:
88+
- temporal
89+
90+
# Task worker with Temporal backend
91+
worker-temporal:
92+
build: .
93+
environment:
94+
- TASK_BACKEND_TYPE=temporal
95+
- TASK_TEMPORAL_HOST=temporal
96+
- TASK_TEMPORAL_PORT=7233
97+
- TASK_TEMPORAL_NAMESPACE=default
98+
- TASK_TEMPORAL_TASK_QUEUE=task-queue
99+
- TASK_WORKER_NAME=temporal-worker-1
100+
- TASK_LOG_LEVEL=INFO
101+
depends_on:
102+
temporal:
103+
condition: service_started
104+
volumes:
105+
- ./logs:/app/logs
106+
restart: unless-stopped
107+
profiles:
108+
- temporal
109+
110+
# Monitoring and observability
111+
prometheus:
112+
image: prom/prometheus:latest
113+
ports:
114+
- "9090:9090"
115+
volumes:
116+
- ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml
117+
- prometheus_data:/prometheus
118+
command:
119+
- '--config.file=/etc/prometheus/prometheus.yml'
120+
- '--storage.tsdb.path=/prometheus'
121+
- '--web.console.libraries=/etc/prometheus/console_libraries'
122+
- '--web.console.templates=/etc/prometheus/consoles'
123+
profiles:
124+
- monitoring
125+
126+
grafana:
127+
image: grafana/grafana:latest
128+
ports:
129+
- "3000:3000"
130+
environment:
131+
- GF_SECURITY_ADMIN_PASSWORD=admin
132+
volumes:
133+
- grafana_data:/var/lib/grafana
134+
- ./monitoring/grafana/dashboards:/etc/grafana/provisioning/dashboards
135+
- ./monitoring/grafana/datasources:/etc/grafana/provisioning/datasources
136+
profiles:
137+
- monitoring
138+
139+
volumes:
140+
redis_data:
141+
postgres_data:
142+
temporal_data:
143+
prometheus_data:
144+
grafana_data:
145+
146+
networks:
147+
default:
148+
name: task-backend-network

0 commit comments

Comments
 (0)