Ejemplo n.º 1
0
    def handle(self, *args, **options):
        book_name = args[0]
        username = args[1]

        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            print('No user found with username <%s>' % username)
            return

        task = get_book_task(book_name)
        task.apply_async(kwargs={'user': user})

        print('Enqueued book "%s" username <%s>' % (book_name, username))
Ejemplo n.º 2
0
def start(request, book_name='yearbook2012', next_view='loading'):
    """
    Spins off the yearbook
    """
    # TODO: find a way to have this effect w/o exposing a public URL?

    # Reject duplicates: look for a task
    # corresponding to that book in the session
    session_async_name = '%s_task_id' % book_name
    if session_async_name not in request.session:
        # Run the specified book
        book_task = get_book_task(book_name)
        book_task_async = book_task.apply_async(kwargs={'user': request.user})
        # Oddly, saving the async_result to session - it disappears.
        # This even though the 'optional_fields_async' survives
        request.session[session_async_name] = book_task_async.id

    # Regardless of book, we need their optional profile fields
    if 'optional_fields_async' not in request.session:
        optional_fields_async = pull_user_profile.apply_async(kwargs={'user': request.user})
        request.session['optional_fields_async'] = optional_fields_async

    return redirect(next_view)