mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
manage.py: Save an extra Django startup by converting one script to a library.
This saves us from spending 200-250ms of CPU time importing Django again just to log that we're running a management command. On `scripts/restart-server`, this saves us from one thundering herd of Django startups when all the queue workers are restarted; but there's still the Django startup for the `manage.py` process itself for each worker, so on a machine with e.g. 2 (virtual) cores the restart is still painful.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
from __future__ import print_function
|
||||
import datetime
|
||||
import errno
|
||||
import logging
|
||||
import os
|
||||
import pwd
|
||||
import re
|
||||
@@ -11,7 +12,7 @@ import sys
|
||||
import time
|
||||
|
||||
if False:
|
||||
from typing import Sequence, Any
|
||||
from typing import Sequence, Text, Any
|
||||
|
||||
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
||||
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
|
||||
@@ -131,3 +132,18 @@ def run(args, **kwargs):
|
||||
ENDC)
|
||||
print()
|
||||
raise
|
||||
|
||||
def log_management_command(cmd, log_path):
|
||||
# type: (Text, Text) -> None
|
||||
log_dir = os.path.dirname(log_path)
|
||||
if not os.path.exists(log_dir):
|
||||
os.makedirs(log_dir)
|
||||
|
||||
formatter = logging.Formatter("%(asctime)s: %(message)s")
|
||||
file_handler = logging.FileHandler(log_path)
|
||||
file_handler.setFormatter(formatter)
|
||||
logger = logging.getLogger("zulip.management")
|
||||
logger.addHandler(file_handler)
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
logger.info("Ran '%s'" % (cmd,))
|
||||
|
||||
Reference in New Issue
Block a user