Debian Codegraph @

django_rq/management/commands/rqsuspend.py

raw
1 import logging
2 import sys
3
4 from django.core.management.base import BaseCommand
5 from rq.suspension import suspend
6
7 from ...queues import get_connection
8
9 log = logging.getLogger(__name__)
10
11
12 class Command(BaseCommand):
13 help = "Suspend all queues."
14
15 def add_arguments(self, parser):
16 parser.add_argument(
17 "--duration",
18 "-d",
19 type=int,
20 help="The duration in seconds to suspend the workers. If blank, workers will be suspended indefinitely",
21 )
22
23 def handle(self, *args, **options):
24 connection = get_connection()
25 duration = options.get("duration")
26
27 if duration is not None and duration < 1:
28 log.error("Duration must be an integer greater than 1")
29 sys.exit(1)
30
31 if duration:
32 suspend(connection, duration)
33 msg = (
34 f"Suspending workers for {duration} seconds. No new jobs will be started "
35 "during that time, but then will automatically resume"
36 )
37 log.info(msg)
38 else:
39 suspend(connection)
40 log.info("Suspending workers. No new jobs will be started. But current jobs will be completed")