forked from rq/django-rq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rqflush asks for confirmation [see rq#218]
- Loading branch information
Showing
2 changed files
with
54 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,42 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from django.utils.six.moves import input | ||
|
||
from django_rq import get_queue | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Removes all queue jobs | ||
Flushes the queue specified as argument | ||
""" | ||
help = __doc__ | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'--noinput', '--no-input', action='store_false', | ||
dest='interactive', default=True, | ||
help='Tells Django to NOT prompt the user for input of any kind.', | ||
) | ||
parser.add_argument('--queue', '-q', dest='queue', default='default', | ||
help='Specify the queue [default]') | ||
|
||
def handle(self, *args, **options): | ||
""" | ||
Queues the function given with the first argument with the | ||
parameters given with the rest of the argument list. | ||
""" | ||
verbosity = int(options.get('verbosity', 1)) | ||
interactive = options['interactive'] | ||
queue = get_queue(options.get('queue')) | ||
queue.empty() | ||
if verbosity: | ||
print('Queue "%s" cleaned' % queue.name) | ||
|
||
if interactive: | ||
confirm = input("""You have requested a flush the "%s" queue. | ||
Are you sure you want to do this? | ||
Type 'yes' to continue, or 'no' to cancel: """ % queue.name) | ||
else: | ||
confirm = 'yes' | ||
|
||
if confirm == 'yes': | ||
queue.empty() | ||
if verbosity: | ||
print('Queue "%s" flushed.' % queue.name) | ||
else: | ||
if verbosity: | ||
print("Flush cancelled.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters