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

@@ -199,6 +199,13 @@ def generate_ideas_core(cluster_id: int, account_id: int = None, progress_callba
Returns: Returns:
Dict with 'success', 'idea_created', 'message', etc. Dict with 'success', 'idea_created', 'message', etc.
""" """
import sys
print("=" * 80, flush=True, file=sys.stdout)
print("[GENERATE IDEAS CORE] Function started", flush=True, file=sys.stdout)
print(f"[GENERATE IDEAS CORE] cluster_id: {cluster_id}", flush=True, file=sys.stdout)
print(f"[GENERATE IDEAS CORE] account_id: {account_id}", flush=True, file=sys.stdout)
print("=" * 80, flush=True, file=sys.stdout)
tracker = ConsoleStepTracker('generate_ideas') tracker = ConsoleStepTracker('generate_ideas')
tracker.init("Task started") tracker.init("Task started")
@@ -279,7 +286,18 @@ def generate_ideas_core(cluster_id: int, account_id: int = None, progress_callba
} }
except Exception as e: except Exception as e:
tracker.error('Exception', str(e), e) import sys
logger.error(f"Error in generate_ideas_core: {str(e)}", exc_info=True) import traceback
return {'success': False, 'error': str(e)} error_msg = str(e)
error_type = type(e).__name__
print("=" * 80, flush=True, file=sys.stdout)
print(f"[GENERATE IDEAS CORE] ERROR: {error_type}: {error_msg}", flush=True, file=sys.stdout)
print("[GENERATE IDEAS CORE] Full traceback:", flush=True, file=sys.stdout)
traceback.print_exc(file=sys.stdout)
print("=" * 80, flush=True, file=sys.stdout)
tracker.error('Exception', error_msg, e)
logger.error(f"Error in generate_ideas_core: {error_msg}", exc_info=True)
return {'success': False, 'error': error_msg, 'error_type': error_type}

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 # Use new framework - always use generate_ideas_core for proper console logging
try: 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 # Use generate_ideas_core which has ConsoleStepTracker built in
result = generate_ideas_core(cluster_id, account_id=account_id) 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'): if result.get('success'):
ideas_created += result.get('idea_created', 0) ideas_created += result.get('idea_created', 0)
logger.info(f"✓ Successfully generated idea for cluster {cluster_id}") 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: 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: 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 # Ideas are already saved by the new framework, just log results
logger.info("=" * 80) logger.info("=" * 80)