Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for custom queue and workers #1939

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions press/docker/config/supervisor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,27 @@ process_name=%(program_name)s-%(process_num)d

{% endif %}

{% if custom_workers %}

{% for worker_name, config in custom_workers.items() %}
[program:-frappe-bench-{{ worker_name }}-worker]
command=bench worker --queue {{ worker_name }}
priority=4
autostart=true
autorestart=true
stdout_logfile=/home/frappe/frappe-bench/logs/{{ worker_name }}.log
stderr_logfile=/home/frappe/frappe-bench/logs/{{ worker_name }}.error.log
user=frappe
stopwaitsecs={{ config["timeout"] }}
directory=/home/frappe/frappe-bench
killasgroup=true
numprocs=1
process_name=%(program_name)s-%(process_num)d
{% endfor %}

{% endif %}


[program:frappe-bench-redis-cache]
command=redis-server /home/frappe/frappe-bench/config/redis-cache.conf
priority=1
Expand Down Expand Up @@ -213,6 +234,13 @@ programs=frappe-bench-frappe-schedule,frappe-bench-frappe-default-worker,frappe-

{% endif %}

{% if custom_workers_group %}

[group:frappe-bench-custom_workers]
programs={{ custom_workers_group}}

{% endif %}

[group:frappe-bench-redis]
programs=frappe-bench-redis-cache,frappe-bench-redis-queue

Expand Down
32 changes: 29 additions & 3 deletions press/press/doctype/deploy_candidate/deploy_candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,8 @@ def _update_app_releases(self) -> None:
app.pullable_release = release_pair["new"]["name"]

def _prepare_build_context(self, no_push: bool):
rg: ReleaseGroup = frappe.get_cache_doc("Release Group", self.group)

repo_path_map = self._clone_repos()
pmf = get_package_manager_files(repo_path_map)
self._run_prebuild_validations_and_update_step(pmf)
Expand All @@ -881,7 +883,7 @@ def _prepare_build_context(self, no_push: bool):

self._copy_config_files()
self._generate_redis_cache_config()
self._generate_supervisor_config()
self._generate_supervisor_config(rg)
self._generate_apps_txt()
self.generate_ssh_keys()

Expand Down Expand Up @@ -1158,13 +1160,37 @@ def _generate_redis_cache_config(self):
content = frappe.render_template(redis_cache_conf_template, {"doc": self}, is_path=True)
f.write(content)

def _generate_supervisor_config(self):
def _generate_supervisor_config(self, rg):
supervisor_conf = os.path.join(self.build_directory, "config", "supervisor.conf")
with open(supervisor_conf, "w") as f:
supervisor_conf_template = "press/docker/config/supervisor.conf"
content = frappe.render_template(supervisor_conf_template, {"doc": self}, is_path=True)
custom_workers = self._get_custom_workers(rg)

content = frappe.render_template(
supervisor_conf_template,
{
"doc": self,
"custom_workers": custom_workers,
"custom_workers_group": self._get_custom_workers_group(custom_workers),
},
is_path=True,
)
f.write(content)

def _get_custom_workers(self, rg):
if rg.common_site_config:
common_site_config = json.loads(rg.common_site_config) or frappe._dict()
return common_site_config.get("workers", frappe._dict())

return frappe._dict()

def _get_custom_workers_group(self, custom_workers):
group = []
if custom_workers:
for worker_name in custom_workers:
group.append(f"frappe-bench-{ worker_name }-worker")
return ", ".join(group)

def _generate_apps_txt(self):
apps_txt = os.path.join(self.build_directory, "apps.txt")
with open(apps_txt, "w") as f:
Expand Down
Loading