Skip to content

Commit bb57d41

Browse files
authored
Expose --max-idle-time RQ flag in rqworker management command (#688)
Django-rq currently does not expose the --max-idle-time flag that python-rq is able to use under the hood to gracefully shut down a worker after a given amount of seconds. Exposing this functionality proves useful in the event when django-rq workers are run within an autoscaling situation where scale-down time cannot be controlled (e.g.: Azure Container Apps). By running the worker with ./manage.py rqworker --max-idle-time 60 default the worker can gracefully shutdown before it gets killed by autoscaling, avoiding interrupted jobs that fail with an error of: Work-horse terminated unexpectedly; waitpid returned 15 (signal 15); Since --max-jobs is already exposed in the rqworker management command, exposing this option is trivial.
1 parent cd05d2f commit bb57d41

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

django_rq/management/commands/rqworker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def add_arguments(self, parser):
4747
help='Turns debug mode on or off.')
4848
parser.add_argument('--max-jobs', action='store', default=None, dest='max_jobs', type=int,
4949
help='Maximum number of jobs to execute')
50+
parser.add_argument('--max-idle-time', action='store', default=None, dest='max_idle_time', type=int,
51+
help='Seconds to wait for job before shutting down')
5052
parser.add_argument('--serializer', action='store', default='rq.serializers.DefaultSerializer', dest='serializer',
5153
help='Specify a custom Serializer.')
5254
parser.add_argument('args', nargs='*', type=str,
@@ -93,7 +95,7 @@ def handle(self, *args, **options):
9395

9496
w.work(
9597
burst=options.get('burst', False), with_scheduler=options.get('with_scheduler', False),
96-
logging_level=level, max_jobs=options['max_jobs']
98+
logging_level=level, max_jobs=options['max_jobs'], max_idle_time=options['max_idle_time']
9799
)
98100
except ConnectionError as e:
99101
self.stderr.write(str(e))

0 commit comments

Comments
 (0)