Skip to content

Commit

Permalink
feat: support for custom queues and workers
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabh6790 committed Jul 10, 2024
1 parent 997ba13 commit c1a2432
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
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_config %}

{% for worker_name, worker_details in custom_workers_config.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={{ worker_details["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_config %}

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

{% endif %}

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

Expand Down
18 changes: 15 additions & 3 deletions press/press/doctype/deploy_candidate/deploy_candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,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 @@ -904,7 +906,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 @@ -1190,15 +1192,25 @@ def _generate_redis_cache_config(self):
)
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"
custom_workers_config = self._get_custom_workers(rg)
content = frappe.render_template(
supervisor_conf_template, {"doc": self}, is_path=True
supervisor_conf_template,
{"doc": self, "custom_workers_config": custom_workers_config},
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()

if "workers" in common_site_config:
return common_site_config["workers"]

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

0 comments on commit c1a2432

Please sign in to comment.