Management of user-triggered asynchronous tasks in Django projects

Project description

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.

Overview

Most of the status updating is handled automatically via Celery’s signals mechanism, but it can be enhanced by:

• Overriding the UserTaskMixin methods such as generate_name and calculate_total_steps for particular types of tasks
• Calling some of the UserTaskStatus methods like increment_completed_steps and set_state from the task implementation

How To Contribute

Contributions are very welcome.

Even though they were written with edx-platform in mind, the guidelines should be followed for Open edX code in general.

Change Log

Unreleased

Removed

• Removed Python 3.5 support.

Chore

• Upgraded celery to latest 5.x version.

[2.2.0] - 2022-01-26

Removed

• Removed Django22,30,31 support.

• Added Django40 support in CI

[2.1.0] - 2021-07-07

• Support for django3.0, 3.1 and 3.2

Changed

• Fixed django admin timeout issue.

Changed

• Fixed minor issue. If links key is not available assign empty list. Added logs.

[2.0.1] - 2021-05-28

• Added celery5.0 testing with tox. Update the import task command compatible with both celery 4.4.7 and celery5.0.

Removed

• Removed python3.5 support.

Changed

• Added celery 5.0 testing using tox. Fix pylint warnings. Update the code accordingly.

Changed

• Updated the deprecated celery import class. New import is compatible with 4.4.7 also.

[1.3.1] - 2020-11-23

• Added support for Django REST Framework 3.10.x through 3.12.x

[1.3.0] - 2020-08-25

• Added support for celery 4

Removed

• Removed code related to Python 2

[1.1.0] - 2020-05-07

• Added support for python 3.8

Removed

• Dropped support for Django < 2.2

Removed

• Dropped Python 2.7 support

[0.3.0] - 2019-12-15

• Added support for Django 2.2

Changed

• start_user_task should only close obsolete connections if the current connection is NOT in an atomic block (which fixes errors on devstack studio/course-publishing).

Changed

• Improve list display for ModelAdmin.

Changed

• Make UserTaskArtifact.url a TextField with a URLValidator instead of a URLField.

Changed

• Change max_length of UserTaskArtifact.url from 200 to 512.

Changed

• Added testing/support for Django 1.11.

Changed

• Slightly improved handling of tasks which start before their status records are committed (due to database transactions). Also documented how to avoid this problem in the first place.

Changed

• Tasks which were explicitly canceled, failed, or retried no longer have their status changed to Succeeded just because the task exited cleanly.
• Celery tasks which fail to import cleanly by name (because they use a custom name which isn’t actually the fully qualified task name) are now just ignored in the before_task_publish signal handler.

Changed

• Add a migration to explicitly reference the setting for artifact file storage. This setting is likely to vary between installations, but doesn’t affect the generated database schema. This change should prevent makemigrations from creating a new migration whenever the setting value changes.

Changed

• Fix Travis configuration for PyPI deployments.
• Switch from the Read the Docs Sphinx theme to the Open edX one for documentation.

[0.1.0] - 2016-10-07

• First attempt to release on PyPI.

Project details

Uploaded source
Uploaded py2 py3