-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3852 from bjester/angry-tasks
Add task helpers and stop enqueuing storage calculation tasks for admins
- Loading branch information
Showing
9 changed files
with
112 additions
and
7 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
48 changes: 48 additions & 0 deletions
48
contentcuration/contentcuration/management/commands/reconcile_change_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,48 @@ | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from contentcuration.celery import app | ||
from contentcuration.models import Change | ||
from contentcuration.models import User | ||
|
||
logging.basicConfig() | ||
logger = logging.getLogger('command') | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Reconciles that unready tasks are marked as reserved or active according to celery control | ||
""" | ||
|
||
def handle(self, *args, **options): | ||
from contentcuration.tasks import apply_channel_changes_task | ||
from contentcuration.tasks import apply_user_changes_task | ||
|
||
active_task_ids = [] | ||
for worker_name, tasks in app.control.inspect().active().items(): | ||
active_task_ids.extend(task['id'] for task in tasks) | ||
for worker_name, tasks in app.control.inspect().reserved().items(): | ||
active_task_ids.extend(task['id'] for task in tasks) | ||
|
||
channel_changes = Change.objects.filter(channel_id__isnull=False, applied=False, errored=False) \ | ||
.order_by('channel_id', 'created_by_id') \ | ||
.values('channel_id', 'created_by_id') \ | ||
.distinct() | ||
for channel_change in channel_changes: | ||
apply_channel_changes_task.revoke(exclude_task_ids=active_task_ids, channel_id=channel_change['channel_id']) | ||
apply_channel_changes_task.fetch_or_enqueue( | ||
User.objects.get(pk=channel_change['created_by_id']), | ||
channel_id=channel_change['channel_id'] | ||
) | ||
|
||
user_changes = Change.objects.filter(channel_id__isnull=True, user_id__isnull=False, applied=False, errored=False) \ | ||
.order_by('user_id', 'created_by_id') \ | ||
.values('user_id', 'created_by_id') \ | ||
.distinct() | ||
for user_change in user_changes: | ||
apply_user_changes_task.revoke(exclude_task_ids=active_task_ids, user_id=user_change['user_id']) | ||
apply_user_changes_task.fetch_or_enqueue( | ||
User.objects.get(pk=user_change['created_by_id']), | ||
user_id=user_change['user_id'] | ||
) |
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
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
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
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
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
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
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