Skip to main content

Management of user-triggered asynchronous tasks in Django projects

Project description

PyPI Travis Codecov Documentation Supported Python versions 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.

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 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

  • Saving task output as instances of the UserTaskArtifact model

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 for details.

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

Reporting Security Issues

Please do not report security issues in public. Please email security@edx.org.

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.

Change Log

Unreleased

[0.1.9] - 2019-08-27

Changed

  • Fix issue with UserTaskArtifactAdmin and UserTaskStatusAdmin where ordering attribute must be a tuple or list.

[0.1.8] - 2019-08-22

Changed

  • Improve list display for ModelAdmin.

[0.1.7] - 2019-05-29

Changed

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

[0.1.6] - 2019-05-29

Changed

  • Upgrade requirements.

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

[0.1.5] - 2017-08-03

Changed

  • Added testing/support for Django 1.11.

[0.1.4] - 2017-01-30

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.

[0.1.3] - 2017-01-03

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.

[0.1.2] - 2016-12-05

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.

[0.1.1] - 2016-10-11

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

Added

  • First attempt to release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-user-tasks-0.1.9.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_user_tasks-0.1.9-py2.py3-none-any.whl (26.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-user-tasks-0.1.9.tar.gz.

File metadata

  • Download URL: django-user-tasks-0.1.9.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.7

File hashes

Hashes for django-user-tasks-0.1.9.tar.gz
Algorithm Hash digest
SHA256 0acf1de28f7a1cf6e93c7627ea3f0d9522ba671ae08e0e12d83f1979d6861597
MD5 0771ffa8ec9d2c4bd9bdb3bd04fda09f
BLAKE2b-256 35ae0963404091c1ec0d7231fa231d1ac9a6043fd9919d0edb08463b31324788

See more details on using hashes here.

File details

Details for the file django_user_tasks-0.1.9-py2.py3-none-any.whl.

File metadata

  • Download URL: django_user_tasks-0.1.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.7

File hashes

Hashes for django_user_tasks-0.1.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 66c9468462f2f8305fe1f0e25f7bbf08732687df47c34f1272fe5f94bdf9ccec
MD5 9673fcb149b51742ddf38a8e29db3297
BLAKE2b-256 df3194e6418e841b603f424c2257e1e6882947d1996e26bebedfb98b080cfabf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page