make archivebox server spawn daphne process instead of runserver

This commit is contained in:
Nick Sweeting 2024-09-06 02:55:06 -07:00
parent f6ca48835a
commit 6e2ddc14df
No known key found for this signature in database

View file

@ -4,13 +4,16 @@ import os
import sys
import shutil
import platform
from django.utils import timezone
import subprocess
from typing import Dict, List, Optional, Iterable, IO, Union
from pathlib import Path
from datetime import date, datetime
from typing import Dict, List, Optional, Iterable, IO, Union
from crontab import CronTab, CronSlices
from django.db.models import QuerySet
from django.utils import timezone
from .cli import (
list_subcommands,
@ -1346,7 +1349,30 @@ def server(runserver_args: Optional[List[str]]=None,
config.SHOW_PROGRESS = False
config.DEBUG = config.DEBUG or debug
if reload or debug:
call_command("runserver", *runserver_args)
else:
host = '127.0.0.1'
port = '8000'
try:
host_and_port = [arg for arg in runserver_args if arg.replace('.', '').replace(':', '').isdigit()][0]
if ':' in host_and_port:
host, port = host_and_port.split(':')
else:
if '.' in host_and_port:
host = host_and_port
else:
port = host_and_port
except IndexError:
pass
try:
subprocess.run(['daphne', '--bind', host, '--port', port, 'archivebox.core.asgi:application'])
except (SystemExit, KeyboardInterrupt):
pass
except Exception as e:
print(e)
@enforce_types