Skip to content

Commit

Permalink
Merge branch 'staging' into v5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Aug 8, 2023
2 parents b09a96d + ffe969b commit ffabe3a
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 128 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: actions/setup-node@v3
if: ${{ matrix.python-version == '3.10' }}
with:
node-version: 18

- uses: actions/setup-node@v3
if: ${{ matrix.python-version == '3.7' }}
with:
node-version: 14

- run: |
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb;
sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb;
Expand Down
2 changes: 1 addition & 1 deletion bench/config/common_site_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def make_ports(bench_path):
"socketio_port": 9000,
"file_watcher_port": 6787,
"redis_queue": 11000,
"redis_socketio": 12000,
"redis_socketio": 13000,
"redis_cache": 13000,
}

Expand Down
10 changes: 1 addition & 9 deletions bench/config/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def generate_config(bench_path):
redis_version = get_redis_version()

ports = {}
for key in ("redis_cache", "redis_queue", "redis_socketio"):
for key in ("redis_cache", "redis_queue"):
ports[key] = urlparse(config[key]).port

write_redis_config(
Expand All @@ -28,12 +28,6 @@ def generate_config(bench_path):
bench_path=bench_path,
)

write_redis_config(
template_name="redis_socketio.conf",
context={"port": ports["redis_socketio"], "redis_version": redis_version},
bench_path=bench_path,
)

write_redis_config(
template_name="redis_cache.conf",
context={
Expand All @@ -56,10 +50,8 @@ def generate_config(bench_path):
# make ACL files
acl_rq_path = os.path.join(bench_path, "config", "redis_queue.acl")
acl_redis_cache_path = os.path.join(bench_path, "config", "redis_cache.acl")
acl_redis_socketio_path = os.path.join(bench_path, "config", "redis_socketio.acl")
open(acl_rq_path, "a").close()
open(acl_redis_cache_path, "a").close()
open(acl_redis_socketio_path, "a").close()


def write_redis_config(template_name, context, bench_path):
Expand Down
32 changes: 23 additions & 9 deletions bench/config/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
import logging
import os

# imports - third party imports
import click

# imports - module imports
import bench
from bench.app import use_rq
from bench.utils import get_bench_name, which
from bench.bench import Bench
from bench.config.common_site_config import (
update_config,
get_gunicorn_workers,
get_default_max_requests,
compute_max_requests_jitter,
get_default_max_requests,
get_gunicorn_workers,
update_config,
)

# imports - third party imports
import click

from bench.utils import get_bench_name, which

logger = logging.getLogger(bench.PROJECT_NAME)

Expand Down Expand Up @@ -48,7 +47,6 @@ def generate_supervisor_config(bench_path, user=None, yes=False, skip_redis=Fals
"redis_server": which("redis-server"),
"node": which("node") or which("nodejs"),
"redis_cache_config": os.path.join(bench_dir, "config", "redis_cache.conf"),
"redis_socketio_config": os.path.join(bench_dir, "config", "redis_socketio.conf"),
"redis_queue_config": os.path.join(bench_dir, "config", "redis_queue.conf"),
"webserver_port": config.get("webserver_port", 8000),
"gunicorn_workers": web_worker_count,
Expand All @@ -59,6 +57,7 @@ def generate_supervisor_config(bench_path, user=None, yes=False, skip_redis=Fals
"bench_cmd": which("bench"),
"skip_redis": skip_redis,
"workers": config.get("workers", {}),
"multi_queue_consumption": can_enable_multi_queue_consumption(bench_path),
}
)

Expand Down Expand Up @@ -91,6 +90,21 @@ def get_supervisord_conf():
return possibility


def can_enable_multi_queue_consumption(bench_path: str) -> bool:
try:
from semantic_version import Version

from bench.utils.app import get_current_version

supported_version = Version(major=14, minor=18, patch=0)

frappe_version = Version(get_current_version("frappe", bench_path=bench_path))

return frappe_version > supported_version
except Exception:
return False


def check_supervisord_config(user=None):
"""From bench v5.x, we're moving to supervisor running as user"""
# i don't think bench should be responsible for this but we're way past this now...
Expand Down
15 changes: 0 additions & 15 deletions bench/config/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def generate_systemd_config(
"redis_server": which("redis-server"),
"node": which("node") or which("nodejs"),
"redis_cache_config": os.path.join(bench_dir, "config", "redis_cache.conf"),
"redis_socketio_config": os.path.join(bench_dir, "config", "redis_socketio.conf"),
"redis_queue_config": os.path.join(bench_dir, "config", "redis_queue.conf"),
"webserver_port": config.get("webserver_port", 8000),
"gunicorn_workers": web_worker_count,
Expand Down Expand Up @@ -244,14 +243,10 @@ def setup_redis_config(bench_info, bench_path):
bench_redis_queue_template = bench.config.env().get_template(
"systemd/frappe-bench-redis-queue.service"
)
bench_redis_socketio_template = bench.config.env().get_template(
"systemd/frappe-bench-redis-socketio.service"
)

bench_redis_target_config = bench_redis_target_template.render(**bench_info)
bench_redis_cache_config = bench_redis_cache_template.render(**bench_info)
bench_redis_queue_config = bench_redis_queue_template.render(**bench_info)
bench_redis_socketio_config = bench_redis_socketio_template.render(**bench_info)

bench_redis_target_config_path = os.path.join(
bench_path, "config", "systemd", bench_info.get("bench_name") + "-redis.target"
Expand All @@ -262,12 +257,6 @@ def setup_redis_config(bench_info, bench_path):
bench_redis_queue_config_path = os.path.join(
bench_path, "config", "systemd", bench_info.get("bench_name") + "-redis-queue.service"
)
bench_redis_socketio_config_path = os.path.join(
bench_path,
"config",
"systemd",
bench_info.get("bench_name") + "-redis-socketio.service",
)

with open(bench_redis_target_config_path, "w") as f:
f.write(bench_redis_target_config)
Expand All @@ -278,9 +267,6 @@ def setup_redis_config(bench_info, bench_path):
with open(bench_redis_queue_config_path, "w") as f:
f.write(bench_redis_queue_config)

with open(bench_redis_socketio_config_path, "w") as f:
f.write(bench_redis_socketio_config)


def _create_symlinks(bench_path):
bench_dir = os.path.abspath(bench_path)
Expand Down Expand Up @@ -319,6 +305,5 @@ def get_unit_files(bench_path):
[bench_name + "-node-socketio", ".service"],
[bench_name + "-redis-cache", ".service"],
[bench_name + "-redis-queue", ".service"],
[bench_name + "-redis-socketio", ".service"],
]
return unit_files
1 change: 0 additions & 1 deletion bench/config/templates/Procfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% if not skip_redis %}
redis_cache: redis-server config/redis_cache.conf
redis_socketio: redis-server config/redis_socketio.conf
redis_queue: redis-server config/redis_queue.conf
{% endif %}
web: bench serve {% if webserver_port -%} --port {{ webserver_port }} {%- endif %}
Expand Down
8 changes: 0 additions & 8 deletions bench/config/templates/redis_socketio.conf

This file was deleted.

76 changes: 9 additions & 67 deletions bench/config/templates/supervisor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ stderr_logfile={{ bench_dir }}/logs/web.error.log
user={{ user }}
directory={{ sites_dir }}

{% if use_rq %}
[program:{{ bench_name }}-frappe-schedule]
command={{ bench_cmd }} schedule
priority=3
Expand All @@ -23,6 +22,7 @@ stderr_logfile={{ bench_dir }}/logs/schedule.error.log
user={{ user }}
directory={{ bench_dir }}

{% if not multi_queue_consumption %}
[program:{{ bench_name }}-frappe-default-worker]
command={{ bench_cmd }} worker --queue default
priority=4
Expand All @@ -36,9 +36,10 @@ directory={{ bench_dir }}
killasgroup=true
numprocs={{ background_workers }}
process_name=%(program_name)s-%(process_num)d
{% endif %}

[program:{{ bench_name }}-frappe-short-worker]
command={{ bench_cmd }} worker --queue short
command={{ bench_cmd }} worker --queue short{{',default' if multi_queue_consumption else ''}}
priority=4
autostart=true
autorestart=true
Expand All @@ -52,7 +53,7 @@ numprocs={{ background_workers }}
process_name=%(program_name)s-%(process_num)d

[program:{{ bench_name }}-frappe-long-worker]
command={{ bench_cmd }} worker --queue long
command={{ bench_cmd }} worker --queue long{{',default,short' if multi_queue_consumption else ''}}
priority=4
autostart=true
autorestart=true
Expand Down Expand Up @@ -81,54 +82,6 @@ numprocs={{ worker_details["background_workers"] or background_workers }}
process_name=%(program_name)s-%(process_num)d
{% endfor %}

{% else %}
[program:{{ bench_name }}-frappe-workerbeat]
command={{ bench_dir }}/env/bin/python -m frappe.celery_app beat -s beat.schedule
priority=3
autostart=true
autorestart=true
stdout_logfile={{ bench_dir }}/logs/workerbeat.log
stderr_logfile={{ bench_dir }}/logs/workerbeat.error.log
user={{ user }}
directory={{ sites_dir }}

[program:{{ bench_name }}-frappe-worker]
command={{ bench_dir }}/env/bin/python -m frappe.celery_app worker -n jobs@%%h -Ofair --soft-time-limit 360 --time-limit 390 --loglevel INFO
priority=4
autostart=true
autorestart=true
stdout_logfile={{ bench_dir }}/logs/worker.log
stderr_logfile={{ bench_dir }}/logs/worker.error.log
user={{ user }}
stopwaitsecs=400
directory={{ sites_dir }}
killasgroup=true

[program:{{ bench_name }}-frappe-longjob-worker]
command={{ bench_dir }}/env/bin/python -m frappe.celery_app worker -n longjobs@%%h -Ofair --soft-time-limit 1500 --time-limit 1530 --loglevel INFO
priority=2
autostart=true
autorestart=true
stdout_logfile={{ bench_dir }}/logs/worker.log
stderr_logfile={{ bench_dir }}/logs/worker.error.log
user={{ user }}
stopwaitsecs=1540
directory={{ sites_dir }}
killasgroup=true

[program:{{ bench_name }}-frappe-async-worker]
command={{ bench_dir }}/env/bin/python -m frappe.celery_app worker -n async@%%h -Ofair --soft-time-limit 1500 --time-limit 1530 --loglevel INFO
priority=2
autostart=true
autorestart=true
stdout_logfile={{ bench_dir }}/logs/worker.log
stderr_logfile={{ bench_dir }}/logs/worker.error.log
user={{ user }}
stopwaitsecs=1540
directory={{ sites_dir }}
killasgroup=true

{% endif %}

{% if not skip_redis %}
[program:{{ bench_name }}-redis-cache]
Expand All @@ -152,18 +105,6 @@ user={{ user }}
directory={{ sites_dir }}
{% endif %}

{% if not skip_redis %}
[program:{{ bench_name }}-redis-socketio]
command={{ redis_server }} {{ redis_socketio_config }}
priority=1
autostart=true
autorestart=true
stdout_logfile={{ bench_dir }}/logs/redis-socketio.log
stderr_logfile={{ bench_dir }}/logs/redis-socketio.error.log
user={{ user }}
directory={{ sites_dir }}
{% endif %}

{% if node %}
[program:{{ bench_name }}-node-socketio]
command={{ node }} {{ bench_dir }}/apps/frappe/socketio.js
Expand All @@ -179,19 +120,20 @@ directory={{ bench_dir }}
[group:{{ bench_name }}-web]
programs={{ bench_name }}-frappe-web {%- if node -%} ,{{ bench_name }}-node-socketio {%- endif%}

{% if use_rq %}

{% if multi_queue_consumption %}

[group:{{ bench_name }}-workers]
programs={{ bench_name }}-frappe-schedule,{{ bench_name }}-frappe-default-worker,{{ bench_name }}-frappe-short-worker,{{ bench_name }}-frappe-long-worker{%- for worker_name in workers -%},{{ bench_name }}-frappe-{{ worker_name }}-worker{%- endfor %}
programs={{ bench_name }}-frappe-schedule,{{ bench_name }}-frappe-short-worker,{{ bench_name }}-frappe-long-worker{%- for worker_name in workers -%},{{ bench_name }}-frappe-{{ worker_name }}-worker{%- endfor %}

{% else %}

[group:{{ bench_name }}-workers]
programs={{ bench_name }}-frappe-workerbeat,{{ bench_name }}-frappe-worker,{{ bench_name }}-frappe-longjob-worker,{{ bench_name }}-frappe-async-worker{%- for worker_name in workers -%},{{ bench_name }}-frappe-{{ worker_name }}-worker{%- endfor %}
programs={{ bench_name }}-frappe-schedule,{{ bench_name }}-frappe-default-worker,{{ bench_name }}-frappe-short-worker,{{ bench_name }}-frappe-long-worker{%- for worker_name in workers -%},{{ bench_name }}-frappe-{{ worker_name }}-worker{%- endfor %}

{% endif %}

{% if not skip_redis %}
[group:{{ bench_name }}-redis]
programs={{ bench_name }}-redis-cache,{{ bench_name }}-redis-queue,{{ bench_name }}-redis-socketio
programs={{ bench_name }}-redis-cache,{{ bench_name }}-redis-queue
{% endif %}
12 changes: 0 additions & 12 deletions bench/config/templates/systemd/frappe-bench-redis-socketio.service

This file was deleted.

2 changes: 1 addition & 1 deletion bench/config/templates/systemd/frappe-bench-redis.target
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Unit]
After=network.target
Wants={{ bench_name }}-redis-cache.service {{ bench_name }}-redis-queue.service {{ bench_name }}-redis-socketio.service
Wants={{ bench_name }}-redis-cache.service {{ bench_name }}-redis-queue.service

[Install]
WantedBy=multi-user.target
1 change: 0 additions & 1 deletion bench/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def assert_virtual_env(self, bench_name):
def assert_config(self, bench_name):
for config, search_key in (
("redis_queue.conf", "redis_queue.rdb"),
("redis_socketio.conf", "redis_socketio.rdb"),
("redis_cache.conf", "redis_cache.rdb"),
):

Expand Down
4 changes: 2 additions & 2 deletions bench/tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_multiple_benches(self):
"socketio_port": 9000,
"file_watcher_port": 6787,
"redis_queue": "redis://localhost:11000",
"redis_socketio": "redis://localhost:12000",
"redis_socketio": "redis://localhost:13000",
"redis_cache": "redis://localhost:13000",
},
)
Expand All @@ -67,7 +67,7 @@ def test_multiple_benches(self):
"socketio_port": 9001,
"file_watcher_port": 6788,
"redis_queue": "redis://localhost:11001",
"redis_socketio": "redis://localhost:12001",
"redis_socketio": "redis://localhost:13001",
"redis_cache": "redis://localhost:13001",
},
)
Expand Down
2 changes: 0 additions & 2 deletions bench/tests/test_setup_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def assert_supervisor_config(self, bench_name, use_rq=True):
f"program:{bench_name}-frappe-web",
f"program:{bench_name}-redis-cache",
f"program:{bench_name}-redis-queue",
f"program:{bench_name}-redis-socketio",
f"group:{bench_name}-web",
f"group:{bench_name}-workers",
f"group:{bench_name}-redis",
Expand Down Expand Up @@ -150,7 +149,6 @@ def assert_supervisor_process(self, bench_name, use_rq=True, disable_production=
# "{bench_name}-web:{bench_name}-node-socketio[\s]+RUNNING",
r"{bench_name}-redis:{bench_name}-redis-cache[\s]+RUNNING",
r"{bench_name}-redis:{bench_name}-redis-queue[\s]+RUNNING",
r"{bench_name}-redis:{bench_name}-redis-socketio[\s]+RUNNING",
]

if use_rq:
Expand Down

0 comments on commit ffabe3a

Please sign in to comment.