Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1bfe998906 | |||
| 3fdbadd454 | |||
| 110327b73e |
Binary file not shown.
Binary file not shown.
+10
-2
@@ -1259,9 +1259,17 @@ def _initialize_scheduler():
|
||||
return
|
||||
|
||||
try:
|
||||
# For multi-worker Gunicorn, check if we're in a reasonable scenario
|
||||
# Using a lock file to ensure only one instance starts the scheduler
|
||||
# For multi-worker Gunicorn, use a lock file to ensure only one instance starts the scheduler
|
||||
# Clean up any stale lock file from previous runs (older than 5 minutes)
|
||||
scheduler_lock_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), '.scheduler_lock')
|
||||
try:
|
||||
if os.path.exists(scheduler_lock_path):
|
||||
lock_age = time.time() - os.path.getmtime(scheduler_lock_path)
|
||||
if lock_age > 300: # 5 minutes - indicates a stale lock from a previous container run
|
||||
os.remove(scheduler_lock_path)
|
||||
app.logger.info(f"Removed stale scheduler lock file (age: {lock_age:.0f}s)")
|
||||
except Exception:
|
||||
pass # If we can't clean up, continue anyway
|
||||
|
||||
try:
|
||||
# Try to create the lock file - only succeeds if it doesn't exist
|
||||
|
||||
+2
-1
@@ -4,7 +4,8 @@ services:
|
||||
container_name: inventarsystem-nginx
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- app
|
||||
app:
|
||||
condition: service_started
|
||||
ports:
|
||||
- "${INVENTAR_HTTP_PORT:-80}:80"
|
||||
- "${INVENTAR_HTTPS_PORT:-443}:443"
|
||||
|
||||
+35
-20
@@ -69,45 +69,60 @@ with open(compose_file, "r", encoding="utf-8") as f:
|
||||
|
||||
out = []
|
||||
in_app = False
|
||||
in_build = False
|
||||
image_set = False
|
||||
app_indent = None
|
||||
app_service_indent = None
|
||||
skip_build_block = False
|
||||
|
||||
def leading_spaces(text):
|
||||
return len(text) - len(text.lstrip(" "))
|
||||
|
||||
for line in lines:
|
||||
stripped = line.lstrip(" ")
|
||||
indent = len(line) - len(stripped)
|
||||
indent = leading_spaces(line)
|
||||
|
||||
if not in_app and re.match(r"^\s{2}app:\s*$", line):
|
||||
if not in_app and re.match(r"^\s*app:\s*$", line):
|
||||
in_app = True
|
||||
image_set = False
|
||||
app_indent = indent
|
||||
app_service_indent = None
|
||||
skip_build_block = False
|
||||
out.append(line)
|
||||
out.append(f" image: {target_image}\n")
|
||||
image_set = True
|
||||
continue
|
||||
|
||||
if in_app:
|
||||
if indent == 2 and re.match(r"^[A-Za-z0-9_-]+:\s*$", stripped):
|
||||
if app_service_indent is None and indent > app_indent:
|
||||
app_service_indent = indent
|
||||
|
||||
if indent <= app_indent and re.match(r"^[A-Za-z0-9_-]+:\s*$", stripped):
|
||||
in_app = False
|
||||
in_build = False
|
||||
app_indent = None
|
||||
app_service_indent = None
|
||||
skip_build_block = False
|
||||
|
||||
if in_app:
|
||||
if in_build:
|
||||
if indent > 4:
|
||||
continue
|
||||
in_build = False
|
||||
if app_service_indent is None:
|
||||
app_service_indent = indent
|
||||
|
||||
if re.match(r"^\s{4}build:\s*$", line):
|
||||
in_build = True
|
||||
if skip_build_block:
|
||||
if indent > app_service_indent:
|
||||
continue
|
||||
skip_build_block = False
|
||||
|
||||
if re.match(rf"^\s{{{app_service_indent}}}build:\s*$", line):
|
||||
skip_build_block = True
|
||||
continue
|
||||
|
||||
if re.match(r"^\s{4}image:\s*", line):
|
||||
if image_set:
|
||||
continue
|
||||
out.append(f" image: {target_image}\n")
|
||||
image_set = True
|
||||
if re.match(rf"^\s{{{app_service_indent}}}image:\s*", line):
|
||||
continue
|
||||
|
||||
if re.match(rf"^\s{{{app_service_indent}}}[A-Za-z0-9_-]+:\s*$", line):
|
||||
out.append(f"{' ' * app_service_indent}image: {target_image}\n")
|
||||
app_service_indent = None
|
||||
|
||||
out.append(line)
|
||||
|
||||
if in_app and app_service_indent is not None:
|
||||
out.append(f"{' ' * app_service_indent}image: {target_image}\n")
|
||||
|
||||
with open(compose_file, "w", encoding="utf-8") as f:
|
||||
f.writelines(out)
|
||||
PY
|
||||
|
||||
Reference in New Issue
Block a user