File: rqsuspend.py

package info (click to toggle)
django-rq 3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 648 kB
  • sloc: python: 3,184; makefile: 7
file content (36 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import logging
import sys

from django.core.management.base import BaseCommand
from rq.suspension import suspend

from ...queues import get_connection

log = logging.getLogger(__name__)

class Command(BaseCommand):
    help = "Suspend all queues."

    def add_arguments(self, parser):
        parser.add_argument(
            "--duration",
            "-d",
            type=int,
            help="The duration in seconds to suspend the workers.  If not provided, workers will be suspended indefinitely",
        )

    def handle(self, *args, **options):
        connection = get_connection()
        duration = options.get("duration")

        if duration is not None and duration < 1:
            log.error("Duration must be an integer greater than 1")
            sys.exit(1)

        if duration:
            suspend(connection, duration)
            msg = f"Suspending workers for {duration} seconds.  No new jobs will be started during that time, but then will automatically resume"
            log.info(msg)
        else:
            suspend(connection)
            log.info("Suspending workers.  No new jobs will be started.  But current jobs will be completed")