cleanup
This commit is contained in:
92
bitbylaw/steps/vmh/beteiligte_sync_event_step.md
Normal file
92
bitbylaw/steps/vmh/beteiligte_sync_event_step.md
Normal file
@@ -0,0 +1,92 @@
|
||||
---
|
||||
type: step
|
||||
category: event
|
||||
name: VMH Beteiligte Sync
|
||||
version: 1.0.0
|
||||
status: placeholder
|
||||
tags: [sync, vmh, beteiligte, event, todo]
|
||||
dependencies: []
|
||||
emits: []
|
||||
subscribes: [vmh.beteiligte.create, vmh.beteiligte.update, vmh.beteiligte.delete]
|
||||
---
|
||||
|
||||
# VMH Beteiligte Sync Event Step
|
||||
|
||||
## Status
|
||||
⚠️ **PLACEHOLDER** - Implementierung noch ausstehend
|
||||
|
||||
## Zweck
|
||||
Verarbeitet Create/Update/Delete-Events für Beteiligte-Entitäten und synchronisiert zwischen EspoCRM und Zielsystem.
|
||||
|
||||
## Config
|
||||
```python
|
||||
{
|
||||
'type': 'event',
|
||||
'name': 'VMH Beteiligte Sync',
|
||||
'subscribes': [
|
||||
'vmh.beteiligte.create',
|
||||
'vmh.beteiligte.update',
|
||||
'vmh.beteiligte.delete'
|
||||
],
|
||||
'emits': [],
|
||||
'flows': ['vmh']
|
||||
}
|
||||
```
|
||||
|
||||
## Geplantes Verhalten
|
||||
|
||||
**Input Events**:
|
||||
```json
|
||||
{
|
||||
"topic": "vmh.beteiligte.create",
|
||||
"data": {
|
||||
"entity_id": "123",
|
||||
"action": "create",
|
||||
"source": "webhook",
|
||||
"timestamp": "..."
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Processing**:
|
||||
1. Fetch full entity data from EspoCRM
|
||||
2. Map to target system format
|
||||
3. Create/Update/Delete in target system
|
||||
4. Remove ID from Redis pending set
|
||||
5. Log success/failure
|
||||
|
||||
## Implementierungs-Aufgaben
|
||||
|
||||
- [ ] EspoCRM API Client erstellen
|
||||
- [ ] Entity-Mapping definieren
|
||||
- [ ] Zielsystem-Integration
|
||||
- [ ] Error-Handling & Retry-Logic
|
||||
- [ ] Redis Cleanup (remove from pending sets)
|
||||
- [ ] Logging & Monitoring
|
||||
|
||||
## Redis Cleanup
|
||||
Nach erfolgreicher Verarbeitung:
|
||||
```python
|
||||
redis.srem('vmh:beteiligte:create_pending', entity_id)
|
||||
redis.srem('vmh:beteiligte:update_pending', entity_id)
|
||||
redis.srem('vmh:beteiligte:delete_pending', entity_id)
|
||||
```
|
||||
|
||||
## Testing (Future)
|
||||
```bash
|
||||
# Manually emit event for testing
|
||||
# (via Motia CLI or test script)
|
||||
```
|
||||
|
||||
## KI Guidance
|
||||
Wenn Sie diesen Step implementieren:
|
||||
1. Erstellen Sie EspoCRM API Client in `services/`
|
||||
2. Definieren Sie Mapping-Logic
|
||||
3. Implementieren Sie Retry-Logic mit exponential backoff
|
||||
4. Cleanen Sie Redis Sets nach Verarbeitung
|
||||
5. Loggen Sie alle Operationen für Audit
|
||||
|
||||
## Related
|
||||
- [webhook/beteiligte_create_api_step.md](webhook/beteiligte_create_api_step.md) - Emits create events
|
||||
- [webhook/beteiligte_update_api_step.md](webhook/beteiligte_update_api_step.md) - Emits update events
|
||||
- [webhook/beteiligte_delete_api_step.md](webhook/beteiligte_delete_api_step.md) - Emits delete events
|
||||
124
bitbylaw/steps/vmh/webhook/beteiligte_create_api_step.md
Normal file
124
bitbylaw/steps/vmh/webhook/beteiligte_create_api_step.md
Normal file
@@ -0,0 +1,124 @@
|
||||
---
|
||||
type: step
|
||||
category: api
|
||||
name: VMH Webhook Beteiligte Create
|
||||
version: 1.0.0
|
||||
status: active
|
||||
tags: [webhook, espocrm, vmh, beteiligte, create]
|
||||
dependencies:
|
||||
- redis
|
||||
emits: [vmh.beteiligte.create]
|
||||
---
|
||||
|
||||
# VMH Webhook Beteiligte Create Step
|
||||
|
||||
## Zweck
|
||||
Empfängt Create-Webhooks von EspoCRM für neue Beteiligte-Entitäten. Dedupliziert via Redis und emittiert Events für asynchrone Verarbeitung.
|
||||
|
||||
## Config
|
||||
```python
|
||||
{
|
||||
'type': 'api',
|
||||
'name': 'VMH Webhook Beteiligte Create',
|
||||
'path': '/vmh/webhook/beteiligte/create',
|
||||
'method': 'POST',
|
||||
'emits': ['vmh.beteiligte.create'],
|
||||
'flows': ['vmh']
|
||||
}
|
||||
```
|
||||
|
||||
## Input
|
||||
```bash
|
||||
POST /vmh/webhook/beteiligte/create
|
||||
Content-Type: application/json
|
||||
|
||||
[
|
||||
{
|
||||
"id": "entity-123",
|
||||
"name": "Max Mustermann",
|
||||
"createdAt": "2026-02-07T10:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "entity-456",
|
||||
"name": "Maria Schmidt"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
**Format**: Array von Entitäten (Batch-Support)
|
||||
|
||||
## Output
|
||||
```json
|
||||
{
|
||||
"status": "received",
|
||||
"action": "create",
|
||||
"new_ids_count": 2,
|
||||
"total_ids_in_batch": 2
|
||||
}
|
||||
```
|
||||
|
||||
## Verhalten
|
||||
|
||||
1. **Extract IDs** von allen Entitäten im Batch
|
||||
2. **Redis Deduplication**:
|
||||
```python
|
||||
pending_key = 'vmh:beteiligte:create_pending'
|
||||
existing_ids = redis.smembers(pending_key)
|
||||
new_ids = input_ids - existing_ids
|
||||
redis.sadd(pending_key, *new_ids)
|
||||
```
|
||||
3. **Emit Events** nur für neue IDs:
|
||||
```python
|
||||
for entity_id in new_ids:
|
||||
await context.emit({
|
||||
'topic': 'vmh.beteiligte.create',
|
||||
'data': {
|
||||
'entity_id': entity_id,
|
||||
'action': 'create',
|
||||
'source': 'webhook',
|
||||
'timestamp': timestamp
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Redis Keys
|
||||
- `vmh:beteiligte:create_pending` (SET): IDs in create queue
|
||||
- No TTL (permanent until processed)
|
||||
|
||||
## Deduplication Logic
|
||||
**Problem**: EspoCRM kann Webhooks mehrfach senden
|
||||
**Solution**: Redis SET speichert alle pending IDs
|
||||
- Neue IDs → Events emittiert
|
||||
- Bereits vorhandene IDs → Skipped
|
||||
|
||||
## Testing
|
||||
```bash
|
||||
# Test webhook
|
||||
curl -X POST "http://localhost:3000/vmh/webhook/beteiligte/create" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '[{"id": "test-123", "name": "Test"}]'
|
||||
|
||||
# Check Redis
|
||||
redis-cli -n 1 SMEMBERS vmh:beteiligte:create_pending
|
||||
|
||||
# Clear Redis (testing)
|
||||
redis-cli -n 1 DEL vmh:beteiligte:create_pending
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
- Invalid JSON: 400 error
|
||||
- Redis unavailable: Loggen, aber nicht crashen (kann zu Duplikaten führen)
|
||||
- Event emission error: Loggen und fortfahren
|
||||
|
||||
## Monitoring
|
||||
```
|
||||
[INFO] VMH Webhook Beteiligte Create empfangen
|
||||
[INFO] Create Entity ID gefunden: entity-123
|
||||
[INFO] 2 neue IDs zur Create-Sync-Queue hinzugefügt
|
||||
[INFO] Create-Event emittiert für ID: entity-123
|
||||
```
|
||||
|
||||
## Related Steps
|
||||
- [beteiligte_update_api_step.md](beteiligte_update_api_step.md) - Update webhooks
|
||||
- [beteiligte_delete_api_step.md](beteiligte_delete_api_step.md) - Delete webhooks
|
||||
- [beteiligte_sync_event_step.md](../beteiligte_sync_event_step.md) - Consumes events
|
||||
Reference in New Issue
Block a user