widgets and other fixes

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-11 15:24:52 +00:00
parent 747770ac58
commit e9369df151
16 changed files with 761 additions and 277 deletions

View File

@@ -1627,44 +1627,66 @@ class AutomationService:
stage_number, approved_count, time_elapsed, 0
)
# Check if auto-publish is enabled and queue approved content for publishing
published_count = 0
# Check if auto-publish is enabled and schedule approved content for publishing
scheduled_count = 0
if publishing_settings.auto_publish_enabled and approved_count > 0:
self.logger.log_stage_progress(
self.run.run_id, self.account.id, self.site.id,
stage_number, f"Auto-publish enabled - queuing {len(content_ids)} content items for publishing"
stage_number, f"Auto-publish enabled - scheduling {len(content_ids)} content items for publishing"
)
# Get WordPress integration for this site
from igny8_core.business.integration.models import SiteIntegration
wp_integration = SiteIntegration.objects.filter(
site=self.site,
platform='wordpress',
is_active=True
).first()
if wp_integration:
from igny8_core.tasks.wordpress_publishing import publish_content_to_wordpress
try:
# Import scheduling helper function
from igny8_core.tasks.publishing_scheduler import _calculate_available_slots
for content_id in content_ids:
try:
# Queue publish task
publish_content_to_wordpress.delay(
content_id=content_id,
site_integration_id=wp_integration.id
)
published_count += 1
except Exception as e:
logger.error(f"[AutomationService] Failed to queue publish for content {content_id}: {str(e)}")
# Get approved content that needs scheduling
approved_content = Content.objects.filter(
id__in=content_ids,
status='approved',
site_status='not_published',
scheduled_publish_at__isnull=True
).order_by('created_at')
if approved_content.exists():
# Calculate available publishing slots
available_slots = _calculate_available_slots(publishing_settings, self.site)
# Assign slots to content
from django.utils import timezone
for i, content in enumerate(approved_content):
if i >= len(available_slots):
self.logger.log_stage_progress(
self.run.run_id, self.account.id, self.site.id,
stage_number, f"No more publishing slots available - {scheduled_count} scheduled, {len(content_ids) - scheduled_count} will be scheduled later"
)
break
# Schedule this content
scheduled_time = available_slots[i]
content.scheduled_publish_at = scheduled_time
content.site_status = 'scheduled'
content.site_status_updated_at = timezone.now()
content.save(update_fields=['scheduled_publish_at', 'site_status', 'site_status_updated_at'])
scheduled_count += 1
logger.info(f"[AutomationService] Scheduled content {content.id} '{content.title}' for {scheduled_time}")
self.logger.log_stage_progress(
self.run.run_id, self.account.id, self.site.id,
stage_number, f"Scheduled {scheduled_count} content items for automatic publishing"
)
else:
self.logger.log_stage_progress(
self.run.run_id, self.account.id, self.site.id,
stage_number, "Approved content already scheduled or published"
)
except Exception as e:
error_msg = f"Failed to schedule content for publishing: {str(e)}"
logger.error(f"[AutomationService] {error_msg}", exc_info=True)
self.logger.log_stage_progress(
self.run.run_id, self.account.id, self.site.id,
stage_number, f"Queued {published_count} content items for WordPress publishing"
)
else:
self.logger.log_stage_progress(
self.run.run_id, self.account.id, self.site.id,
stage_number, "No active WordPress integration found - skipping auto-publish"
stage_number, error_msg
)
self.run.stage_7_result = {
@@ -1674,7 +1696,7 @@ class AutomationService:
'content_ids': content_ids,
'time_elapsed': time_elapsed,
'in_progress': False,
'auto_published_count': published_count if publishing_settings.auto_publish_enabled else 0,
'scheduled_count': scheduled_count if publishing_settings.auto_publish_enabled else 0,
'auto_publish_enabled': publishing_settings.auto_publish_enabled,
}
self.run.status = 'completed'
@@ -1685,7 +1707,7 @@ class AutomationService:
cache.delete(f'automation_lock_{self.site.id}')
logger.info(f"[AutomationService] Stage 7 complete: {approved_count} content pieces approved" +
(f", {published_count} queued for publishing" if published_count > 0 else " (ready for publishing)"))
(f", {scheduled_count} scheduled for publishing" if scheduled_count > 0 else " (ready for manual publishing)"))
def pause_automation(self):
"""Pause current automation run"""