Skip to content

Commit

Permalink
fix: worker group string
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabh6790 committed Oct 18, 2024
1 parent 52df999 commit b003813
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
10 changes: 5 additions & 5 deletions press/docker/config/supervisor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ process_name=%(program_name)s-%(process_num)d

{% endif %}

{% if custom_workers_config %}
{% if custom_workers %}

{% for worker_name, worker_details in custom_workers_config.items() %}
{% for worker_name, config in custom_workers.items() %}
[program:-frappe-bench-{{ worker_name }}-worker]
command=bench worker --queue {{ worker_name }}
priority=4
Expand All @@ -174,7 +174,7 @@ 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={{ worker_details["timeout"] }}
stopwaitsecs={{ config["timeout"] }}
directory=/home/frappe/frappe-bench
killasgroup=true
numprocs=1
Expand Down Expand Up @@ -234,10 +234,10 @@ programs=frappe-bench-frappe-schedule,frappe-bench-frappe-default-worker,frappe-

{% endif %}

{% if custom_workers_config %}
{% if custom_workers_group %}

[group:frappe-bench-custom_workers]
programs={%- for worker_name in workers -%}frappe-bench-{{ worker_name }}-worker,{%- endfor %}
programs={{ custom_workers_group}}

{% endif %}

Expand Down
22 changes: 17 additions & 5 deletions press/press/doctype/deploy_candidate/deploy_candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,20 +1164,32 @@ 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"
custom_workers_config = self._get_custom_workers(rg)
custom_workers = self._get_custom_workers(rg)

content = frappe.render_template(
supervisor_conf_template,
{"doc": self, "custom_workers_config": custom_workers_config},
{
"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(self.common_site_config) or frappe._dict()
common_site_config = json.loads(rg.common_site_config) or frappe._dict()
return common_site_config.get("workers", frappe._dict())

return frappe._dict()

if "workers" in common_site_config:
return common_site_config["workers"]
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")
Expand Down

0 comments on commit b003813

Please sign in to comment.