-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add management commands to move and flush tasks in queues
- Loading branch information
1 parent
d29694f
commit 208f725
Showing
4 changed files
with
62 additions
and
0 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
20 changes: 20 additions & 0 deletions
20
...roject_name}}/{{cookiecutter.django_default_app_name}}/management/commands/flush_queue.py
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.core.management.base import BaseCommand | ||
from {{cookiecutter.django_project_name}}.celery import flush_tasks, get_num_tasks_in_queue | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Flush task queue.' | ||
|
||
def add_arguments(self, parser) -> None: | ||
parser.add_argument('queue', type=str, help='Queue name to flush') | ||
|
||
def handle(self, *args, **kwargs): | ||
queue_name = kwargs['queue'] | ||
|
||
num_tasks = get_num_tasks_in_queue(queue_name) | ||
self.stdout.write(f'Found {num_tasks} tasks in "{queue_name}" queue') | ||
if not num_tasks: | ||
return | ||
|
||
flush_tasks(queue_name) | ||
self.stdout.write('All done') |
22 changes: 22 additions & 0 deletions
22
...project_name}}/{{cookiecutter.django_default_app_name}}/management/commands/move_tasks.py
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.core.management.base import BaseCommand | ||
from {{cookiecutter.django_project_name}}.celery import move_tasks, get_num_tasks_in_queue | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Reschedule dead letter tasks.' | ||
|
||
def add_arguments(self, parser) -> None: | ||
parser.add_argument('source_queue', type=str, help='Source queue name') | ||
parser.add_argument('destination_queue', type=str, help='Destination queue name') | ||
|
||
def handle(self, *args, **kwargs): | ||
source_queue = kwargs['source_queue'] | ||
destination_queue = kwargs['destination_queue'] | ||
|
||
num_tasks = get_num_tasks_in_queue(source_queue) | ||
self.stdout.write(f'Found {num_tasks} tasks in "{source_queue}" queue') | ||
if not num_tasks: | ||
return | ||
|
||
move_tasks(source_queue, destination_queue) | ||
self.stdout.write('All done') |
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