Skip to content

Commit

Permalink
fix: Correct environment variable usage for worker names
Browse files Browse the repository at this point in the history
Signed-off-by: Alok Singh <[email protected]>
  • Loading branch information
Xieyt committed Jan 29, 2025
1 parent 52dbd81 commit 81b5001
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Docker/frappe/launch_supervisor_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ trap cleanup SIGTERM
if [[ -n "${SUPERVISOR_SERVICE_CONFIG_FILE_NAME:-}" ]]; then
# Use the provided config file name
CONFIG_FILE_NAME="${SUPERVISOR_SERVICE_CONFIG_FILE_NAME}"
elif [[ -n "${WORKER_NAME:-}" ]]; then
CONFIG_FILE_NAME="${WORKER_NAME}.workers.fm.supervisor.conf"
elif [[ -n "${SERVICE_NAME:-}" ]]; then
# Generate config file name from SERVICE_NAME
CONFIG_FILE_NAME="${SERVICE_NAME}.fm.supervisor.conf"
else
# Neither variable is set, error out
emer "Either SUPERVISOR_SERVICE_CONFIG_FILE_NAME or SERVICE_NAME env must be given."
emer "Either SUPERVISOR_SERVICE_CONFIG_FILE_NAME or WORKER_NAME or SERVICE_NAME env must be given."
fi

# Set SUPERVISOR_SERVICE_CONFIG_FILE_NAME for use in rest of the script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def migrate_workers_compose(self, bench: MigrationBench):
bench.workers_compose_project.compose_file_manager.set_service_command(
service_name, 'launch_supervisor_service.sh'
)
envs[service_name]["SERVICE_NAME"] = service_name
envs[service_name]["WORKER_NAME"] = service_name

# volume remove :cached
volumes = bench.workers_compose_project.compose_file_manager.get_all_services_volumes()
Expand Down Expand Up @@ -189,6 +189,11 @@ def migrate_admin_tools_compose(self, bench: MigrationBench):

richprint.change_head("Migrating admin-tools compose")

### change the redis releated hosts in common_site_config
### change the mailhog releated hosts in common_site_config
### remove admin-tools.conf from nginx/custom
### supervisord config not avaible after migration

# remove mailhog
if 'mailhog' in admin_tool_compose_project.compose_file_manager.yml['services']:
del admin_tool_compose_project.compose_file_manager.yml['services']['mailhog']
Expand Down
2 changes: 1 addition & 1 deletion frappe_manager/site_manager/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def sync_bench_common_site_config(self, services_db_host: str, services_db_port:
"db_port": services_db_port,
"redis_cache": f"redis://{container_prefix}{CLI_DEFAULT_DELIMETER}redis-cache:6379",
"redis_queue": f"redis://{container_prefix}{CLI_DEFAULT_DELIMETER}redis-queue:6379",
"redis_socketio": f"redis://{container_prefix}{CLI_DEFAULT_DELIMETER}redis-cache:6379",
"redis_socketio": f"redis://{container_prefix}{CLI_DEFAULT_DELIMETER}redis-socketio:6379",
}
self.set_common_bench_config(common_site_config_data)

Expand Down
20 changes: 11 additions & 9 deletions frappe_manager/site_manager/workers_manager/SiteWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ def is_new_workers_added(self) -> bool:
prev_workers = self.compose_project.compose_file_manager.get_services_list()
prev_workers.sort()
expected_workers = self.get_expected_workers()

# get custom workers from common_site_config.json
# common_site_config_data = self.bench.get_common_bench_config()

# if 'workers' in common_site_config_data:
# custom_workers: List[str] = common_site_config_data['workers'].keys()
# for worker in custom_workers:
# worker = f'{worker}-worker'
# if worker not in prev_workers:
# return False
common_site_config_data = self.bench.get_common_bench_config()

if 'workers' in common_site_config_data:
custom_workers: List[str] = common_site_config_data['workers'].keys()
for worker in custom_workers:
worker = f'{worker}-worker'
if worker not in prev_workers:
return False
return prev_workers == expected_workers

else:
return False

Expand All @@ -89,7 +91,7 @@ def generate_compose(self):
# setting environments
worker_config["environment"]["USERID"] = os.getuid()
worker_config["environment"]["USERGROUP"] = os.getgid()
worker_config["environment"]["SERVICE_NAME"] = worker
worker_config["environment"]["WORKER_NAME"] = worker

self.compose_project.compose_file_manager.yml["services"][worker] = worker_config

Expand Down

0 comments on commit 81b5001

Please sign in to comment.