Skip to content

Commit 5b9ebc8

Browse files
committed
fix:support all worker arguments
1 parent ddece64 commit 5b9ebc8

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

scheduler/management/commands/rqworker.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919
3: logging.DEBUG,
2020
}
2121

22+
WORKER_ARGUMENTS = {
23+
"name",
24+
"default_result_ttl",
25+
"connection",
26+
"exc_handler",
27+
"exception_handlers",
28+
"default_worker_ttl",
29+
"maintenance_interval",
30+
"job_class",
31+
"queue_class",
32+
"log_job_description",
33+
"job_monitoring_interval",
34+
"disable_default_exception_handler",
35+
"prepare_for_work",
36+
"serializer",
37+
"work_horse_killed_handler",
38+
}
39+
2240

2341
def reset_db_connections():
2442
for c in connections.all():
@@ -80,30 +98,29 @@ def add_arguments(self, parser):
8098
parser.add_argument("--sentry-ca-certs", action="store", dest="sentry_ca_certs", help="Path to CA certs file")
8199

82100
def handle(self, **options):
83-
queues = options.get("queues", [])
101+
queues = options.pop("queues", [])
84102
if not queues:
85103
queues = [
86104
"default",
87105
]
88106
click.echo(f"Starting worker for queues {queues}")
89-
pidfile = options.get("pidfile")
107+
pidfile = options.pop("pidfile")
90108
if pidfile:
91109
with open(os.path.expanduser(pidfile), "w") as fp:
92110
fp.write(str(os.getpid()))
93111

94112
# Verbosity is defined by default in BaseCommand for all commands
95-
verbosity = options.get("verbosity", 1)
113+
verbosity = options.pop("verbosity", 1)
96114
log_level = VERBOSITY_TO_LOG_LEVEL.get(verbosity, logging.INFO)
97115
setup_loghandlers(log_level)
98116

117+
init_options = {k: v for k, v in options.items() if k in WORKER_ARGUMENTS}
118+
99119
try:
100120
# Instantiate a worker
101121
w = create_worker(
102122
*queues,
103-
name=options["name"],
104-
job_class=options.get("job_class"),
105-
default_worker_ttl=options["worker_ttl"],
106-
fork_job_execution=options["fork_job_execution"],
123+
**init_options
107124
)
108125

109126
# Close any opened DB connection before any fork

0 commit comments

Comments
 (0)