56 lines
1.2 KiB
Markdown
Executable file
56 lines
1.2 KiB
Markdown
Executable file
# Jobs Python
|
|
|
|
Shared infrastructure for async job management and service clients.
|
|
|
|
## Features
|
|
|
|
- **Job Management**: Track async jobs with status, progress, and results
|
|
- **Storage Backends**: In-memory (dev) and Redis (production)
|
|
- **Service Clients**: HTTP clients with retry logic and job polling
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
pip install -e .
|
|
|
|
# With Redis support
|
|
pip install -e ".[redis]"
|
|
```
|
|
|
|
## Usage
|
|
|
|
```python
|
|
from jobs import Job, InMemoryJobStorage, RedisJobStorage
|
|
|
|
# Create storage
|
|
storage = InMemoryJobStorage() # Dev
|
|
# storage = RedisJobStorage(redis_url="redis://localhost:6379") # Prod
|
|
|
|
# Create and track job
|
|
job = Job(service="translation", job_type="batch_translate")
|
|
await storage.create(job)
|
|
|
|
job.start()
|
|
await storage.update(job)
|
|
|
|
job.update_progress("translating", completed=5, total=10)
|
|
await storage.update(job)
|
|
|
|
job.complete({"translations": [...]})
|
|
await storage.update(job)
|
|
```
|
|
|
|
## Service Client
|
|
|
|
```python
|
|
from jobs import ServiceClient
|
|
|
|
client = ServiceClient(
|
|
base_url="http://localhost:8004",
|
|
service_name="translation",
|
|
)
|
|
|
|
# Health check
|
|
if await client.is_healthy():
|
|
result = await client.post("/translate/", json={"text": "Hello", ...})
|
|
```
|