This commit is contained in:
alorig
2025-11-10 00:13:11 +05:00
parent 46920aa313
commit 9fe6153c22
2 changed files with 71 additions and 5 deletions

View File

@@ -926,15 +926,63 @@ def auto_generate_ideas_task(self, cluster_ids: List[int], account_id: int = Non
# Use new framework - always use generate_ideas_core for proper console logging
try:
import sys
print(f"[CELERY TASK] Calling generate_ideas_core for cluster {cluster_id}...", flush=True, file=sys.stdout)
# Use generate_ideas_core which has ConsoleStepTracker built in
result = generate_ideas_core(cluster_id, account_id=account_id)
print(f"[CELERY TASK] generate_ideas_core returned: success={result.get('success')}, error={result.get('error')}", flush=True, file=sys.stdout)
if result.get('success'):
ideas_created += result.get('idea_created', 0)
logger.info(f"✓ Successfully generated idea for cluster {cluster_id}")
print(f"[CELERY TASK] ✓ Successfully generated idea for cluster {cluster_id}", flush=True, file=sys.stdout)
else:
logger.error(f"✗ Failed to generate idea for cluster {cluster_id}: {result.get('error')}")
error_msg = result.get('error', 'Unknown error')
logger.error(f"✗ Failed to generate idea for cluster {cluster_id}: {error_msg}")
print(f"[CELERY TASK] ✗ Failed to generate idea for cluster {cluster_id}: {error_msg}", flush=True, file=sys.stdout)
# Update task state with error for this cluster
self.update_state(
state='PROGRESS',
meta={
'current': idx + 1,
'total': total_clusters,
'percentage': progress_pct,
'message': f'Error generating idea for cluster "{cluster.name}": {error_msg}',
'phase': 'error',
'current_item': cluster.name,
'error': error_msg,
'error_type': result.get('error_type', 'GenerationError')
}
)
except Exception as e:
logger.error(f"✗ Error generating idea for cluster {cluster_id}: {str(e)}", exc_info=True)
import sys
import traceback
error_msg = str(e)
error_type = type(e).__name__
print("=" * 80, flush=True, file=sys.stdout)
print(f"[CELERY TASK] EXCEPTION in generate_ideas_core call: {error_type}: {error_msg}", flush=True, file=sys.stdout)
print("[CELERY TASK] Full traceback:", flush=True, file=sys.stdout)
traceback.print_exc(file=sys.stdout)
print("=" * 80, flush=True, file=sys.stdout)
logger.error(f"✗ Error generating idea for cluster {cluster_id}: {error_msg}", exc_info=True)
# Update task state with exception
self.update_state(
state='PROGRESS',
meta={
'current': idx + 1,
'total': total_clusters,
'percentage': progress_pct,
'message': f'Exception generating idea for cluster "{cluster.name}": {error_msg}',
'phase': 'error',
'current_item': cluster.name,
'error': error_msg,
'error_type': error_type
}
)
# Ideas are already saved by the new framework, just log results
logger.info("=" * 80)