mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Adds management command to revoke preview image tasks
This commit is contained in:
parent
dc14670a2c
commit
b812a5c73e
1 changed files with 31 additions and 0 deletions
31
bookwyrm/management/commands/revoke_preview_image_tasks.py
Normal file
31
bookwyrm/management/commands/revoke_preview_image_tasks.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
""" Actually let's not generate those preview images """
|
||||
import json
|
||||
from django.core.management.base import BaseCommand
|
||||
from bookwyrm.tasks import app
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""Find and revoke image tasks"""
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def handle(self, *args, **options):
|
||||
"""reveoke nonessential low priority tasks"""
|
||||
types = [
|
||||
"bookwyrm.preview_images.generate_edition_preview_image_task",
|
||||
"bookwyrm.preview_images.generate_user_preview_image_task",
|
||||
]
|
||||
self.stdout.write(" | Finding tasks of types:")
|
||||
self.stdout.write("\n".join(types))
|
||||
with app.pool.acquire(block=True) as conn:
|
||||
tasks = conn.default_channel.client.lrange("low_priority", 0, -1)
|
||||
self.stdout.write(f" | Found {len(tasks)} task(s) in low priority queue")
|
||||
|
||||
revoke_ids = []
|
||||
for task in tasks:
|
||||
task_json = json.loads(task)
|
||||
task_type = task_json.get("headers", {}).get("task")
|
||||
if task_type in types:
|
||||
revoke_ids.append(task_json.get("headers", {}).get("id"))
|
||||
self.stdout.write(".", ending="")
|
||||
self.stdout.write(f"\n | Revoking {len(revoke_ids)} task(s)")
|
||||
app.control.revoke(revoke_ids)
|
Loading…
Reference in a new issue