Skip to content

Commit

Permalink
Add django command for flushing huey storage
Browse files Browse the repository at this point in the history
- useful in case the task locks get stuck: if this happens,
the courses will not be built until the lock is flushed from the storage
  • Loading branch information
lainets authored and markkuriekkinen committed Aug 31, 2022
1 parent a5f79dc commit 1f65aa3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ setting. Memcached is a good option for this. You may need to increase the cache
object size for it to work properly. The default object size of 1MB will work fine for small to
medium size courses but larger courses may require more space, 5MB should be fine for all but the
most exceptional cases. The total size needed depends on the number of courses and their sizes,
a surefire way is to take the maximum object size and multiply it by the number of courses. Note
that you need to install the appropriate python package for the cache, see
a surefire way is to take the maximum object size and multiply it by the number of courses. Note
that you need to install the appropriate python package for the cache, see
https://docs.djangoproject.com/en/3.2/topics/cache/. The requirements_prod.txt file contains the
python package for memcached.

If a course build is stuck locked (can be seen in huey logs (repeated locked messages), and the
build is stuck in RUNNING and PENDING states), the task lock can be flushed with the flush_huye
django admin command.
Empty file added builder/management/__init__.py
Empty file.
Empty file.
19 changes: 19 additions & 0 deletions builder/management/commands/flush_huey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.core.management.base import BaseCommand
from huey.contrib.djhuey import HUEY


class Command(BaseCommand):
help = "Flushes whole Huey storage or a build lock for a single course. Helpful if a task lock got stuck."

def add_arguments(self, parser):
parser.add_argument('course_key', nargs='?', type=str, default="")

def handle(self, *args, **options):
# Check by arguments.
if options["course_key"]:
storage_key = HUEY.lock_task(f"build-{options['course_key']}")._key
HUEY.delete(storage_key)
self.stdout.write(f"Deleted lock for course with key {options['course_key']}")
else:
HUEY.flush()
self.stdout.write(f"Flushed Huey storage")

0 comments on commit 1f65aa3

Please sign in to comment.