@@ -236,7 +236,7 @@ def install_deps(c: Connection | DockerRunner | Context, config: dict) -> None:
236236 logger .info ("Installing Python dependencies..." )
237237 c .run (
238238 f"bash -c 'source { venv_dir } /bin/activate && "
239- f"cd { deploy_path } && pip install -r requirements.txt > /dev/null '" ,
239+ f"cd { deploy_path } && pip install -r requirements.txt'" ,
240240 pty = True
241241 )
242242
@@ -350,15 +350,17 @@ def collect_static(
350350 pty = True
351351 )
352352
353+ # ruff: noqa: PLR0912
353354def restart_services (
354355 c : Connection | DockerRunner | Context ,
355356 config : dict
356357 ) -> None :
357358 """
358- Start or restart Gunicorn for the project.
359+ Start or restart Gunicorn and Celery workers for the project.
359360
360- Uses the bash script 'start_services.sh' to handle the restart process.
361- If the script doesn't exist, logs a warning and returns.
361+ Uses the bash scripts 'start_services.sh' and 'start_celery_workers.sh' to
362+ handle the restart process.
363+ If either script doesn't exist, logs a warning and continues.
362364
363365 :param c: Fabric runner or connection object.
364366 :type c: Union[Connection, DockerRunner, Context]
@@ -370,48 +372,98 @@ def restart_services(
370372
371373 # Get site name from config
372374 site = config ['name' ]
373- script_path = "/scripts/start_services.sh"
374375
375- # Check if the script exists
376- check_script = c .run (
377- f"test -f { script_path } && echo 'exists' || echo 'not_found'" ,
376+ # Define script paths
377+ gunicorn_script_path = "/scripts/start_services.sh"
378+ celery_script_path = "/scripts/start_celery_workers.sh"
379+
380+ # First, restart Gunicorn services
381+ # Check if the Gunicorn script exists
382+ check_gunicorn_script = c .run (
383+ f"test -f { gunicorn_script_path } && echo 'exists' || echo 'not_found'" ,
378384 hide = True ,
379385 warn = True
380386 )
381- if check_script is None :
387+ if check_gunicorn_script is None :
382388 logger .warning (
383- f"Script { script_path } not found. Skipping service restart."
389+ f"Script { gunicorn_script_path } not found. "
390+ f"Skipping Gunicorn restart."
384391 )
385- return
386-
387- script_exists = check_script .stdout .strip () == "exists"
392+ else :
393+ gunicorn_script_exists = check_gunicorn_script .stdout .strip () == "exists"
388394
389- if not script_exists :
395+ if not gunicorn_script_exists :
396+ logger .warning (
397+ f"Script { gunicorn_script_path } not found. "
398+ f"Skipping Gunicorn restart."
399+ )
400+ else :
401+ logger .info (f"Restarting Gunicorn services for { site } ..." )
402+
403+ # Determine if we should restart a specific site or all sites
404+ if site and site != "all" :
405+ # Restart specific site
406+ result = c .run (f"{ gunicorn_script_path } { site } " , warn = True )
407+ else :
408+ # Restart all sites
409+ result = c .run (f"{ gunicorn_script_path } " , warn = True )
410+
411+ # Check if the command executed successfully
412+ if result and not result .failed :
413+ logger .info (
414+ f"Gunicorn services for { site } restarted successfully"
415+ )
416+ else :
417+ logger .error (f"Failed to restart Gunicorn services for { site } " )
418+ error_details = (
419+ result .stderr if result and hasattr (result , 'stderr' )
420+ else 'Unknown error'
421+ )
422+ logger .error (f"Error details: { error_details } " )
423+
424+ # Second, restart Celery workers
425+ # Check if the Celery script exists
426+ check_celery_script = c .run (
427+ f"test -f { celery_script_path } && echo 'exists' || echo 'not_found'" ,
428+ hide = True ,
429+ warn = True
430+ )
431+ if check_celery_script is None :
390432 logger .warning (
391- f"Script { script_path } not found. Skipping service restart."
433+ f"Script { celery_script_path } not found. "
434+ f"Skipping Celery workers restart."
392435 )
393- return
394-
395- logger .info (f"Restarting services for { site } using bash script..." )
396-
397- # Determine if we should restart a specific site or all sites
398- if site and site != "all" :
399- # Restart specific site
400- result = c .run (f"{ script_path } { site } " , warn = True )
401436 else :
402- # Restart all sites
403- result = c .run (f"{ script_path } " , warn = True )
437+ celery_script_exists = check_celery_script .stdout .strip () == "exists"
404438
405- # Check if the command executed successfully
406- if result and not result .failed :
407- logger .info (f"Services for { site } restarted successfully" )
408- else :
409- logger .error (f"Failed to restart services for { site } " )
410- error_details = (
411- result .stderr if result and hasattr (result , 'stderr' )
412- else 'Unknown error'
413- )
414- logger .error (f"Error details: { error_details } " )
439+ if not celery_script_exists :
440+ logger .warning (
441+ f"Script { celery_script_path } not found. "
442+ f"Skipping Celery workers restart."
443+ )
444+ else :
445+ logger .info (f"Restarting Celery workers for { site } ..." )
446+
447+ # Determine if we should restart a specific site or all sites
448+ if site and site != "all" :
449+ # Restart specific site
450+ result = c .run (f"{ celery_script_path } { site } " , warn = True )
451+ else :
452+ # Restart all sites
453+ result = c .run (f"{ celery_script_path } " , warn = True )
454+
455+ # Check if the command executed successfully
456+ if result and not result .failed :
457+ logger .info (
458+ f"Celery workers for { site } restarted successfully"
459+ )
460+ else :
461+ logger .error (f"Failed to restart Celery workers for { site } " )
462+ error_details = (
463+ result .stderr if result and hasattr (result , 'stderr' )
464+ else 'Unknown error'
465+ )
466+ logger .error (f"Error details: { error_details } " )
415467
416468def set_writable_dirs (
417469 c : Connection | DockerRunner | Context ,
0 commit comments