Add sync strategy documentation and templates for bidirectional sync between EspoCRM and Advoware

- Introduced SYNC_STRATEGY_ARCHIVE.md detailing the sync process, status values, and flow for updating entities from EspoCRM to Advoware and vice versa.
- Created SYNC_TEMPLATE.md as a guide for implementing new syncs, including field definitions, mapper examples, sync utilities, event handlers, and cron jobs.
- Added README_SYNC.md for the Beteiligte sync event handler, outlining its functionality, event subscriptions, optimizations, error handling, and performance metrics.
This commit is contained in:
2026-02-07 15:54:13 +00:00
parent 8550107b89
commit ae1d96f767
12 changed files with 1162 additions and 1069 deletions

View File

@@ -90,24 +90,35 @@ async def handler(context):
context.logger.info("✅ Keine Entities benötigen Sync")
return
# EMITTIERE EVENT FÜR JEDEN BETEILIGTEN
emitted_count = 0
# OPTIMIERT: Batch emit mit asyncio.gather für Parallelität
context.logger.info(f"🚀 Emittiere {len(entity_ids)} Events parallel...")
for entity_id in entity_ids:
try:
await context.emit({
'topic': 'vmh.beteiligte.sync_check',
'data': {
'entity_id': entity_id,
'action': 'sync_check',
'source': 'cron',
'timestamp': datetime.datetime.now().isoformat()
}
})
emitted_count += 1
except Exception as e:
context.logger.error(f"❌ Fehler beim Emittieren für {entity_id}: {e}")
emit_tasks = [
context.emit({
'topic': 'vmh.beteiligte.sync_check',
'data': {
'entity_id': entity_id,
'action': 'sync_check',
'source': 'cron',
'timestamp': datetime.datetime.now().isoformat()
}
})
for entity_id in entity_ids
]
# Parallel emit mit error handling
results = await asyncio.gather(*emit_tasks, return_exceptions=True)
# Count successes and failures
emitted_count = sum(1 for r in results if not isinstance(r, Exception))
failed_count = sum(1 for r in results if isinstance(r, Exception))
if failed_count > 0:
context.logger.warning(f"⚠️ {failed_count} Events konnten nicht emittiert werden")
# Log first few errors
for i, result in enumerate(results[:5]): # Log max 5 errors
if isinstance(result, Exception):
context.logger.error(f" Entity {entity_ids[i]}: {result}")
context.logger.info(f"✅ Cron fertig: {emitted_count}/{len(entity_ids)} Events emittiert")