Skip to content

Commit

Permalink
feat: add direct config module calling
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Nov 26, 2024
1 parent 14a3303 commit cf3eec6
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 9 deletions.
21 changes: 21 additions & 0 deletions bench/config/common_site_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,24 @@ def make_pid_folder(bench_path):
pids_path = os.path.join(bench_path, "config", "pids")
if not os.path.exists(pids_path):
os.makedirs(pids_path)


def main(bench_path):
setup_config(bench_path)

if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(
description="Configure the common_site_config file for the bench.",
usage="""
python -m bench.config.common_site_config <bench_path>
<bench_path> : The path to the bench directory.
"""
)

parser.add_argument("bench_path", help="The path to the bench directory.")

args = parser.parse_args()

main(args.bench_path)
60 changes: 56 additions & 4 deletions bench/config/procfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import click

import bench
from bench.app import use_rq
from bench.bench import Bench
from bench.utils import which


def setup_procfile(bench_path, yes=False, skip_redis=False):
def setup_procfile(bench_path, yes=False, skip_redis=False, skip_web=False, skip_watch=os.environ.get("CI"), skip_socketio=False, skip_schedule=False, with_coverage=False):
config = Bench(bench_path).conf
procfile_path = os.path.join(bench_path, "Procfile")

Expand All @@ -25,14 +24,67 @@ def setup_procfile(bench_path, yes=False, skip_redis=False):
.get_template("Procfile")
.render(
node=which("node") or which("nodejs"),
use_rq=use_rq(bench_path),
webserver_port=config.get("webserver_port"),
CI=os.environ.get("CI"),
skip_redis=skip_redis,
skip_web=skip_web,
skip_watch=skip_watch,
skip_socketio=skip_socketio,
skip_schedule=skip_schedule,
with_coverage=with_coverage,
workers=config.get("workers", {}),
is_mac=is_mac,
)
)

with open(procfile_path, "w") as f:
f.write(procfile)

def main(bench_path, skip_redis, skip_web, skip_watch, skip_socketio, skip_schedule, with_coverage):
setup_procfile(
bench_path,
skip_redis=skip_redis,
skip_web=skip_web,
skip_watch=skip_watch,
skip_socketio=skip_socketio,
skip_schedule=skip_schedule,
with_coverage=with_coverage,
)

if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(
description="Configure the procfile for the bench.",
usage="""
python -m bench.config.procfile <bench_path> [options]
<bench_path> : The path to the bench directory.
Options:
--skip-redis : Skip Redis configuration.
--skip-web : Skip web server configuration.
--skip-watch : Skip watch process configuration.
--skip-socketio : Skip Socket.IO configuration.
--skip-schedule : Skip schedule configuration.
--with-coverage : Enable coverage.
"""
)

parser.add_argument("bench_path", help="The path to the bench directory.")
parser.add_argument("--skip-redis", action="store_true", help="Skip Redis configuration.")
parser.add_argument("--skip-web", action="store_true", help="Skip web server configuration.")
parser.add_argument("--skip-watch", action="store_true", default=os.environ.get("CI"), help="Skip watch process configuration.")
parser.add_argument("--skip-socketio", action="store_true", help="Skip Socket.IO configuration.")
parser.add_argument("--skip-schedule", action="store_true", help="Skip schedule configuration.")
parser.add_argument("--with-coverage", action="store_true", help="Enable coverage.")

args = parser.parse_args()

main(
args.bench_path,
args.skip_redis,
args.skip_web,
args.skip_watch,
args.skip_socketio,
args.skip_schedule,
args.with_coverage
)
20 changes: 20 additions & 0 deletions bench/config/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,23 @@ def get_max_redis_memory():
except ValueError:
max_mem = int(subprocess.check_output(["sysctl", "-n", "hw.memsize"]).strip())
return max(50, int((max_mem / (1024.0**2)) * 0.05))

def main(bench_path):
generate_config(bench_path)

if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(
description="Configure the redis configuration files for the bench.",
usage="""
python -m bench.config.redis <bench_path>
<bench_path> : The path to the bench directory.
"""
)

parser.add_argument("bench_path", help="The path to the bench directory.")

args = parser.parse_args()

main(args.bench_path)
13 changes: 8 additions & 5 deletions bench/config/templates/Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
redis_cache: redis-server config/redis_cache.conf
redis_queue: redis-server config/redis_queue.conf
{% endif %}
web: bench serve {% if webserver_port -%} --port {{ webserver_port }} {%- endif %}

{% if not skip_web %}
web: bench serve {% if with_coverage -%} --with-coverage {%- endif %} {% if webserver_port -%} --port {{ webserver_port }} {%- endif %}
{% endif %}
{% if not skip_socketio %}
socketio: {{ node }} apps/frappe/socketio.js

{% if not CI %}
{% endif %}
{% if not skip_watch %}
watch: bench watch
{% endif %}

{% if not skip_schedule %}
schedule: bench schedule
{% endif %}
worker: {{ 'OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES NO_PROXY=*' if is_mac else '' }} bench worker 1>> logs/worker.log 2>> logs/worker.error.log
{% for worker_name, worker_details in workers.items() %}
worker_{{ worker_name }}: {{ 'OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES NO_PROXY=*' if is_mac else '' }} bench worker --queue {{ worker_name }} 1>> logs/worker.log 2>> logs/worker.error.log
Expand Down

0 comments on commit cf3eec6

Please sign in to comment.