AI AUtomtaion, Schudelign and publishign fromt and backe end refoactr
This commit is contained in:
@@ -77,6 +77,15 @@ class AutomationViewSet(viewsets.ViewSet):
|
||||
'stage_6_batch_size': config.stage_6_batch_size,
|
||||
'within_stage_delay': config.within_stage_delay,
|
||||
'between_stage_delay': config.between_stage_delay,
|
||||
# Per-run limits (0 = unlimited)
|
||||
'max_keywords_per_run': config.max_keywords_per_run,
|
||||
'max_clusters_per_run': config.max_clusters_per_run,
|
||||
'max_ideas_per_run': config.max_ideas_per_run,
|
||||
'max_tasks_per_run': config.max_tasks_per_run,
|
||||
'max_content_per_run': config.max_content_per_run,
|
||||
'max_images_per_run': config.max_images_per_run,
|
||||
'max_approvals_per_run': config.max_approvals_per_run,
|
||||
'max_credits_per_run': config.max_credits_per_run,
|
||||
'last_run_at': config.last_run_at,
|
||||
'next_run_at': config.next_run_at,
|
||||
})
|
||||
@@ -153,6 +162,18 @@ class AutomationViewSet(viewsets.ViewSet):
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
|
||||
# Per-run limits (0 = unlimited)
|
||||
for field in ['max_keywords_per_run', 'max_clusters_per_run', 'max_ideas_per_run',
|
||||
'max_tasks_per_run', 'max_content_per_run', 'max_images_per_run',
|
||||
'max_approvals_per_run', 'max_credits_per_run']:
|
||||
if field in request.data:
|
||||
try:
|
||||
value = int(request.data[field])
|
||||
if value >= 0: # Allow 0 (unlimited) or positive numbers
|
||||
setattr(config, field, value)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
|
||||
config.save()
|
||||
|
||||
return Response({
|
||||
@@ -175,6 +196,15 @@ class AutomationViewSet(viewsets.ViewSet):
|
||||
'stage_6_batch_size': config.stage_6_batch_size,
|
||||
'within_stage_delay': config.within_stage_delay,
|
||||
'between_stage_delay': config.between_stage_delay,
|
||||
# Per-run limits (0 = unlimited)
|
||||
'max_keywords_per_run': config.max_keywords_per_run,
|
||||
'max_clusters_per_run': config.max_clusters_per_run,
|
||||
'max_ideas_per_run': config.max_ideas_per_run,
|
||||
'max_tasks_per_run': config.max_tasks_per_run,
|
||||
'max_content_per_run': config.max_content_per_run,
|
||||
'max_images_per_run': config.max_images_per_run,
|
||||
'max_approvals_per_run': config.max_approvals_per_run,
|
||||
'max_credits_per_run': config.max_credits_per_run,
|
||||
'last_run_at': config.last_run_at,
|
||||
'next_run_at': config.next_run_at,
|
||||
})
|
||||
@@ -267,6 +297,17 @@ class AutomationViewSet(viewsets.ViewSet):
|
||||
try:
|
||||
service = AutomationService.from_run_id(run_id)
|
||||
service.pause_automation()
|
||||
|
||||
# CRITICAL FIX: Log pause to automation log files
|
||||
try:
|
||||
service.logger.log_stage_progress(
|
||||
service.run.run_id, service.account.id, service.site.id,
|
||||
service.run.current_stage, f"Automation paused by user at stage {service.run.current_stage}"
|
||||
)
|
||||
except Exception as log_err:
|
||||
# Don't fail the pause if logging fails
|
||||
pass
|
||||
|
||||
return Response({'message': 'Automation paused'})
|
||||
except AutomationRun.DoesNotExist:
|
||||
return Response(
|
||||
@@ -1613,6 +1654,22 @@ class AutomationViewSet(viewsets.ViewSet):
|
||||
run.completed_at = timezone.now()
|
||||
run.save(update_fields=['status', 'cancelled_at', 'completed_at'])
|
||||
|
||||
# CRITICAL FIX: Release the lock so user can start new automation
|
||||
from django.core.cache import cache
|
||||
cache.delete(f'automation_lock_{run.site.id}')
|
||||
|
||||
# Log the cancellation to automation log files
|
||||
try:
|
||||
from igny8_core.business.automation.services.automation_logger import AutomationLogger
|
||||
logger = AutomationLogger()
|
||||
logger.log_stage_progress(
|
||||
run.run_id, run.account.id, run.site.id, run.current_stage,
|
||||
f"Automation cancelled by user at stage {run.current_stage}"
|
||||
)
|
||||
except Exception as log_err:
|
||||
# Don't fail the cancellation if logging fails
|
||||
pass
|
||||
|
||||
return Response({
|
||||
'message': 'Automation cancelled',
|
||||
'status': run.status,
|
||||
|
||||
Reference in New Issue
Block a user