django-user-tasks
django-user-tasks copied to clipboard
A Django application for managing user-triggered asynchronous tasks.
django-user-tasks
.. image:: https://img.shields.io/pypi/v/django-user-tasks.svg :target: https://pypi.python.org/pypi/django-user-tasks/ :alt: PyPI
.. image:: https://github.com/openedx/django-user-tasks/workflows/Python%20CI/badge.svg?branch=master :target: https://github.com/openedx/django-user-tasks/actions?query=workflow%3A%22Python+CI%22 :alt: CI
.. image:: http://codecov.io/github/edx/django-user-tasks/coverage.svg?branch=master :target: http://codecov.io/github/edx/django-user-tasks?branch=master :alt: Codecov
.. image:: https://readthedocs.org/projects/django-user-tasks/badge/?version=latest :target: http://django-user-tasks.readthedocs.io/en/latest/ :alt: Documentation
.. image:: https://img.shields.io/pypi/pyversions/django-user-tasks.svg :target: https://pypi.python.org/pypi/django-user-tasks/ :alt: Supported Python versions
.. image:: https://img.shields.io/github/license/edx/django-user-tasks.svg :target: https://github.com/openedx/django-user-tasks/blob/master/LICENSE.txt :alt: License
django-user-tasks is a reusable Django application for managing user-triggered asynchronous tasks. It provides a status page for each such task, which includes a meaningful progress indicator if the task is currently being executed and provides any appropriate text and/or links for output once the task is complete.
In Open edX, such tasks include operations such as exporting or importing a
course, sending an email to all the students in a course, uploading a video,
and other tasks which often take too long to perform during a single web
request (as outlined in OEP-3_). However, this has been written with the
intention of being useful in a variety of Django projects outside the Open edX
platform as well.
Note that this library was created as a consolidation of lessons learned from implementing such tasks in various parts of the Open edX code base. They don't yet all use this library, but the plan is to over time refactor many of them to do so.
.. _OEP-3: https://open-edx-proposals.readthedocs.io/en/latest/oeps/oep-0003.html
Overview
django-user-tasks is currently a wrapper for Celery_ (although the hope is
that it could also be extended to also support channels_ and other
asynchronous task queues). By extending the provided UserTask class (or
adding UserTaskMixin to an existing Task subclass) and providing a
user_id task argument, the task's status is stored in a database table
separate from the Celery broker and result store. This UserTaskStatus
model allows for full database queries of the tasks that users are most likely
to care about while not imposing any restrictions on the Celery configuration
most appropriate for the site's overall needs for asynchronous task
processing.
Most of the status updating is handled automatically via Celery's signals_
mechanism, but it can be enhanced by:
- Overriding the
UserTaskMixinmethods such asgenerate_nameandcalculate_total_stepsfor particular types of tasks - Calling some of the
UserTaskStatusmethods likeincrement_completed_stepsandset_statefrom the task implementation - Saving task output as instances of the
UserTaskArtifactmodel
.. _Celery: http://www.celeryproject.org/ .. _channels: https://channels.readthedocs.io/en/latest/ .. _signals: http://docs.celeryproject.org/en/latest/userguide/signals.html
Documentation
The full documentation is at https://django-user-tasks.readthedocs.org.
License
The code in this repository is licensed under the Apache Software License 2.0 unless otherwise noted.
Please see LICENSE.txt for details.
How To Contribute
Contributions are very welcome.
Please read How To Contribute <https://github.com/openedx/.github/blob/master/CONTRIBUTING.md>_ for details.
Reporting Security Issues
Please do not report security issues in public. Please email [email protected].
Getting Help
Have a question about this repository, or about Open edX in general? Please
refer to this list of resources_ if you need any assistance.
.. _list of resources: https://open.edx.org/getting-help