<commit_before>from movie.models import Movie
from sorl.thumbnail import get_thumbnail

for movie in Movie.objects.all():
    try:
        get_thumbnail(movie.image, 'x285')
    except Exception, e:
        print "Error processing Movie ID: %s" % (str(movie.pk))
        print e<commit_msg>Rewrote thumbnails as a celery task<commit_after>from movie.models import Movie
from sorl.thumbnail import get_thumbnail
from celery import task

def cache_thumbnails():
    num_movies = Movie.objects.all().count()
    per_section = num_movies / 12
    indexes = range(0, num_movies, per_section)
    for i in range(len(indexes))[:-1]:
        cache_subset.delay(indexes[i], indexes[i+1])


@task(ignore_result=True)
def cache_subset(start, end, callback=None)
    for movie in Movie.objects.all()[start:end]:
        try:
            get_thumbnail(movie.image, 'x285')
        except Exception, e:
            print "Error processing Movie ID: %s" % (str(movie.pk))
            print e
{'fraction_non_alphanumeric': 0.10860655737704918, 'fraction_numerical': 0.011270491803278689, 'mean_word_length': 3.361607142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2995725', 'n_tokens_mistral': 321, 'n_tokens_neox': 305, 'n_words': 84}