2
2
import logging .config
3
3
import os
4
4
import sys
5
+ from multiprocessing import Process
5
6
from signal import Signals
6
7
from typing import TYPE_CHECKING , cast
7
8
20
21
watch_help = 'Watch a directory and reload the worker upon changes.'
21
22
verbose_help = 'Enable verbose output.'
22
23
logdict_help = "Import path for a dictionary in logdict form, to configure Arq's own logging."
24
+ workers_help = 'Number of worker processes to spawn'
23
25
24
26
25
27
@click .command ('arq' )
28
30
@click .option ('--burst/--no-burst' , default = None , help = burst_help )
29
31
@click .option ('--check' , is_flag = True , help = health_check_help )
30
32
@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 )
31
34
@click .option ('-v' , '--verbose' , is_flag = True , help = verbose_help )
32
35
@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 :
34
39
"""
35
40
Job queues in python with asyncio and redis.
36
41
@@ -49,8 +54,15 @@ def cli(*, worker_settings: str, burst: bool, check: bool, watch: str, verbose:
49
54
else :
50
55
kwargs = {} if burst is None else {'burst' : burst }
51
56
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 )
53
62
else :
63
+ if workers > 1 :
64
+ for _ in range (workers - 1 ):
65
+ Process (target = run_worker , args = (worker_settings_ ,), kwargs = kwargs ).start ()
54
66
run_worker (worker_settings_ , ** kwargs )
55
67
56
68
0 commit comments