Public
Authored by 💻

UWSGI spooler example leveraging django

Usage:

    pks = qs.values_list('pk')
    Task(callback='yourmodule.yourcallback', env={'pks': pks}, total=len(pks))()

yourmodule:

    def yourcallback(task):
        task.user  # auto-filled if you have django-threadlocals
        task.creation_ip # same
        task.env  # the picklefield, be carefull with SECURITY !! don't let users inject shit !! unpickling aint safe
        for pk in task.env['pks']:
            task.progress += 1
            task.save()

            # sub task
            sub_task = Task(parent=task, callback='update_stuff', env=dict(pk=pk))
            sub_task()

            # not sure how we're going to do progress aggregation from subtask yet
            # oh well, we'll see about that when there's a sponsor
Edited
django_uwsgi_spooler_models.py 3.29 KB
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment