fixes related to automation and celery schedules

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-18 12:22:27 +00:00
parent 3a65fb919a
commit 879ef6ff06
9 changed files with 358 additions and 27 deletions

View File

@@ -115,13 +115,30 @@ class AutomationViewSet(viewsets.ViewSet):
site=site
)
# Update fields
# Update fields - track if schedule changed
schedule_changed = False
if 'is_enabled' in request.data:
if config.is_enabled != request.data['is_enabled']:
schedule_changed = True
config.is_enabled = request.data['is_enabled']
if 'frequency' in request.data:
if config.frequency != request.data['frequency']:
schedule_changed = True
config.frequency = request.data['frequency']
if 'scheduled_time' in request.data:
config.scheduled_time = request.data['scheduled_time']
new_time = request.data['scheduled_time']
if str(config.scheduled_time) != str(new_time):
schedule_changed = True
config.scheduled_time = new_time
# Reset last_run_at and recalculate next_run_at if any schedule setting changed
if schedule_changed:
config.last_run_at = None
# Recalculate next_run_at based on new schedule
from igny8_core.business.automation.tasks import _calculate_next_run
from django.utils import timezone
config.next_run_at = _calculate_next_run(config, timezone.now())
# Stage enabled toggles
if 'stage_1_enabled' in request.data:
config.stage_1_enabled = request.data['stage_1_enabled']
@@ -1921,3 +1938,35 @@ class AutomationViewSet(viewsets.ViewSet):
},
'initial_snapshot': initial_snapshot
}
@extend_schema(tags=['Automation'])
@action(detail=False, methods=['get'], url_path='server_time')
def server_time(self, request):
"""
GET /api/v1/automation/server_time/
Get current server time (UTC) used for all automation scheduling.
Returns:
- server_time: Current UTC timestamp (ISO 8601 format)
- server_time_formatted: Human-readable UTC time
- timezone: Server timezone setting (always UTC)
- celery_timezone: Celery task timezone setting
- use_tz: Whether Django is timezone-aware
Note: All automation schedules (scheduled_time) are in UTC.
When user sets "02:00", the automation runs at 02:00 UTC.
"""
from django.conf import settings
now = timezone.now()
return Response({
'server_time': now.isoformat(),
'server_time_formatted': now.strftime('%H:%M'),
'server_time_date': now.strftime('%Y-%m-%d'),
'server_time_time': now.strftime('%H:%M:%S'),
'timezone': settings.TIME_ZONE,
'celery_timezone': getattr(settings, 'CELERY_TIMEZONE', settings.TIME_ZONE),
'use_tz': settings.USE_TZ,
'note': 'All automation schedules are in UTC. When you set "02:00", the automation runs at 02:00 UTC.'
})