File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
django_lightweight_queue/management/commands Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ import argparse
2
+
3
+ from django .core .management .base import BaseCommand , CommandError
4
+
5
+ from ...types import QueueName
6
+ from ...utils import get_backend
7
+ from ...backends .base import BackendWithClear
8
+
9
+
10
+ class Command (BaseCommand ):
11
+ help = """
12
+ Command to clear work on a redis-backed queue.
13
+
14
+ All pending jobs will be deleted from the queue. In flight jobs won't be
15
+ affected.
16
+ """ # noqa:A003 # inherited name
17
+
18
+ def add_arguments (self , parser : argparse .ArgumentParser ) -> None :
19
+ parser .add_argument (
20
+ 'queue' ,
21
+ action = 'store' ,
22
+ help = "The queue to pause." ,
23
+ )
24
+
25
+ parser .add_argument (
26
+ '--yes' ,
27
+ 'skip_prompt' ,
28
+ action = 'store_true' ,
29
+ help = "Skip confirmation prompt." ,
30
+ )
31
+
32
+ def handle (self , queue : QueueName , skip_prompt : bool = False , ** options : object ) -> None :
33
+
34
+ backend = get_backend (queue )
35
+
36
+ if not isinstance (backend , BackendWithClear ):
37
+ raise CommandError (
38
+ "Configured backend '{}.{}' doesn't support clearing" .format (
39
+ type (backend ).__module__ ,
40
+ type (backend ).__name__ ,
41
+ ),
42
+ )
43
+
44
+ if not skip_prompt :
45
+ prompt = "Clear all jobs from queue {}) [y/N] " .format (queue )
46
+ choice = input (prompt ).lower ()
47
+
48
+ if choice != "y" :
49
+ raise CommandError ("Aborting" )
50
+
51
+ backend .clear (queue )
You can’t perform that action at this time.
0 commit comments