-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Management command to set
Repeater.max_workers
.
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
corehq/motech/repeaters/management/commands/set_repeater_workers.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,37 @@ | ||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
|
||
from corehq.motech.repeaters.models import Repeater | ||
|
||
|
||
class Command(BaseCommand): | ||
help = f""" | ||
Sets Repeater.max_workers, which is the number of Celery workers | ||
allocated to sending a batch of repeat records. Set to "0" to use | ||
the default, which is {settings.DEFAULT_REPEATER_WORKERS}. Set to | ||
"1" to send repeat records chronologically, one at a time. The | ||
maximum value is {settings.MAX_REPEATER_WORKERS}. | ||
""" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('domain') | ||
parser.add_argument('repeater_id') | ||
parser.add_argument('max_workers', type=int) | ||
|
||
def handle(self, domain, repeater_id, max_workers, *args, **options): | ||
if not 0 <= max_workers <= settings.MAX_REPEATER_WORKERS: | ||
self.stderr.write( | ||
'max_workers must be between 0 and ' | ||
f'{settings.MAX_REPEATER_WORKERS}.' | ||
) | ||
# Use QuerySet.update() to avoid a race condition if the | ||
# repeater is currently in use. | ||
rows = ( | ||
Repeater.objects | ||
.filter(domain=domain, id=repeater_id) | ||
.update(max_workers=max_workers) | ||
) | ||
if not rows: | ||
self.stderr.write( | ||
f'Repeater {repeater_id} was not found in domain {domain}.' | ||
) |
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