Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Keep cron jobs added in the same second apart

Juan Denis151d84f3b36c
diff --git a/backend/app/services/cron_service.py b/backend/app/services/cron_service.py
index 92e576c9..b04208d3 100644
--- a/backend/app/services/cron_service.py
+++ b/backend/app/services/cron_service.py
@@ -8,6 +8,7 @@ for cross-platform compatibility.
import os
import re
import sys
+import secrets
import shlex
import subprocess
import platform
@@ -423,8 +424,8 @@ class CronService:
_auto_capture_cron('add_job')
- # Generate job ID
- job_id = f"job_{datetime.now().strftime('%Y%m%d%H%M%S')}"
+ # The random tail keeps two jobs added in the same second apart.
+ job_id = f"job_{datetime.now().strftime('%Y%m%d%H%M%S')}_{secrets.token_hex(3)}"
metadata = cls._load_jobs_metadata()
diff --git a/backend/tests/test_cron_preview.py b/backend/tests/test_cron_preview.py
index 4fd621cb..c385094e 100644
--- a/backend/tests/test_cron_preview.py
+++ b/backend/tests/test_cron_preview.py
@@ -97,10 +97,6 @@ def test_add_job_stores_application_id(tmp_path, monkeypatch):
assert jobs[0]['application_id'] == 42
[email protected](reason="plan 42: recovery regression - add_job generates a "
- "second-precision job_id (job_%Y%m%d%H%M%S), so two adds in "
- "the same second collide and only one job persists; the "
- "finer-grained id from plan 34 was lost")
def test_clear_application(tmp_path, monkeypatch):
import app.services.cron_service as mod
monkeypatch.setattr(mod.CronService, 'is_linux', classmethod(lambda cls: False))