22import logging .config
33import os
44import sys
5+ from multiprocessing import Process
56from signal import Signals
67from typing import TYPE_CHECKING , cast
78
2021watch_help = 'Watch a directory and reload the worker upon changes.'
2122verbose_help = 'Enable verbose output.'
2223logdict_help = "Import path for a dictionary in logdict form, to configure Arq's own logging."
24+ workers_help = 'Number of worker processes to spawn'
2325
2426
2527@click .command ('arq' )
2830@click .option ('--burst/--no-burst' , default = None , help = burst_help )
2931@click .option ('--check' , is_flag = True , help = health_check_help )
3032@click .option ('--watch' , type = click .Path (exists = True , dir_okay = True , file_okay = False ), help = watch_help )
33+ @click .option ('-w' , '--workers' , type = int , default = 1 , help = workers_help )
3134@click .option ('-v' , '--verbose' , is_flag = True , help = verbose_help )
3235@click .option ('--custom-log-dict' , type = str , help = logdict_help )
33- def cli (* , worker_settings : str , burst : bool , check : bool , watch : str , verbose : bool , custom_log_dict : str ) -> None :
36+ def cli (
37+ * , worker_settings : str , burst : bool , check : bool , watch : str , workers : int , verbose : bool , custom_log_dict : str
38+ ) -> None :
3439 """
3540 Job queues in python with asyncio and redis.
3641
@@ -49,8 +54,15 @@ def cli(*, worker_settings: str, burst: bool, check: bool, watch: str, verbose:
4954 else :
5055 kwargs = {} if burst is None else {'burst' : burst }
5156 if watch :
52- asyncio .run (watch_reload (watch , worker_settings_ ))
57+ coroutine = watch_reload (watch , worker_settings_ )
58+ if workers > 1 :
59+ for _ in range (workers - 1 ):
60+ Process (target = asyncio .run , args = (coroutine ,)).start ()
61+ asyncio .run (coroutine )
5362 else :
63+ if workers > 1 :
64+ for _ in range (workers - 1 ):
65+ Process (target = run_worker , args = (worker_settings_ ,), kwargs = kwargs ).start ()
5466 run_worker (worker_settings_ , ** kwargs )
5567
5668
0 commit comments