Fixed TG messages quotes. Fixed sync tasks loop.

This commit is contained in:
Ultradesu
2025-09-17 13:34:46 +03:00
parent c4057180b9
commit f304825836

View File

@@ -481,6 +481,7 @@ class ServerAdmin(PolymorphicParentModelAdmin, BaseVPNAdmin):
task_key = f"sync_server_{server.id}"
# Use Celery's inspect to check active tasks (optional, for better UX)
try:
inspect = current_app.control.inspect()
active_tasks = inspect.active()
@@ -489,8 +490,10 @@ class ServerAdmin(PolymorphicParentModelAdmin, BaseVPNAdmin):
if active_tasks:
for worker, tasks in active_tasks.items():
for task_info in tasks:
if task_info.get('name') == 'sync_server_users' and \
server.id in str(task_info.get('args', [])):
if task_info.get('name') == 'sync_server_users':
# Check if server.id is in the task args
task_args = task_info.get('args', [])
if task_args and len(task_args) > 0 and task_args[0] == server.id:
task_already_running = True
break
@@ -501,6 +504,9 @@ class ServerAdmin(PolymorphicParentModelAdmin, BaseVPNAdmin):
level=messages.WARNING
)
continue
except Exception as e:
# If we can't check active tasks, just proceed
logger.debug(f"Could not check active tasks: {e}")
# Avoid scheduling duplicate tasks in this batch
if server.id in scheduled_tasks: