Skip to main content

Django application to manage common django management tasks asynchronously, via the Django admin interface, using Redis Queue.

NOTE: Right now, django-eztaskmanager is built to play nice with RQ (Redis Queue). It does the job, and does it well. But I know some of you out there swear by Celery, and I hear you. It's on my radar and I'm knee-deep in code working to get it integrated. So, keep an eye out for updates!

eztaskmanager is a port and an evolution of our previous django-uwsgi-taskmanager, so thanks to the authors there.

Main features:

  • use standard django management commands as tasks templates,
  • import available management commands through a meta-management command, as possible templates for tasks,
  • start and stop tasks manually via admin,
  • schedule point and periodic tasks via django admin,
  • use RQ (rq + rq-scheduler) or Celery (celery + celery-beat) for queue management,
  • check or download the generated reports/logs,
  • live logs streaming view, with filters on errors and warnings for tasks debugging,
  • get notifications via Slack or email when a task succeeds or fails.

See full documentation at http://django-eztaskmanager.rtfd.io/

Installation

  1. Install the app with pip:

    • via PyPI:

      pip install django-eztaskmanager

    • or via GitHub:

      pip install git+https://github.com/openpolis/django-eztaskmanager.git

  2. Add "eztaskmanager" to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        "django.contrib.admin",
        # ...
        "eztaskmanager",
    ]
    
  3. Run python manage.py migrate to create the taskmanager tables.

  4. Run python manage.py collectcommands --excludecore to import taskmanager commands.

  5. Include the taskmanager URLConf (for the log viewers) in your project urls.py like this (optional):

    from django.contrib import admin
    from django.urls import include, path
    
    urlpatterns = [
        path("admin/", admin.site.urls),
        path('eztaskmanager/', include('eztaskmanager.urls'))
    ]
    
  6. Set parameters in your settings file as below (optional):

    # eztaskmanager
    # EZTASKMANAGER_QUEUE_SERVICE_TYPE = 'RQ'
    # EZTASKMANAGER_N_LINES_IN_REPORT_LOG = 10
    # EZTASKMANAGER_N_REPORTS_INLINE = 10
    # EZTASKMANAGER_SHOW_LOGVIEWER_LINK = True
    # EZTASKMANAGER_USE_FILTER_COLLAPSE = True
    # EZTASKMANAGER_NOTIFICATION_HANDLERS = {}
    # EZTASKMANAGER_BASE_URL = None
    EZTASKMANAGER_NOTIFICATION_HANDLERS = {
        "email-errors": {
            "class": "eztaskmanager.services.notifications.EmailNotificationHandler",
            "level": "failure",
            "from_email": "admin@example.com",
            "recipients": ["admin@example.com", ],
        },
    }
    EZTASKMANAGER_N_LINES_IN_REPORT_LOG = 5
    

Usage

You just need to install django-eztaskmanager in your Django Project and run collectcommands as described. Django ezaskmanager will collect all the commands and make them available for asynchronous scheduling in the admin.

If you need a new asynchronous task, just write a standard custom Django command using eztaskmanager.services.logger.LogEnabledCommand in places of django.core.management.base.BaseCommand, and synchronize the app. Then go to the admin page and schedule it.

You can disable commands from the admin, and let users (with limited permissions) schedule only the available ones.

NOTE: RQ or Celery workers and schedulers (rq-scheduler or celery-beat) need to be up and running

Enabling notifications

To enable Slack notifications support for failing tasks, you have to first install the required packages, which are not included by default. To do that, just:

pip install django-eztaskmanager[notifications]

This will install the django-eztaskmanager package from PyPI, including the optional dependencies required to make Slack notifications work.

Email notifications are instead handled using Django django.core.mail module, so no further dependencies are needed and they should work out of the box, given you have at least one email backend properly configured.

Then, you have to configure the following settings:

  • EZTASKMANAGER_NOTIFICATIONS_SLACK_TOKEN, which must be set with you own Slack token as string.
  • EZTASKMANAGER_NOTIFICATIONS_SLACK_CHANNELS, a list of strings representing the names or ids of the channels which will receive the notifications.
  • EZTASKMANAGER_NOTIFICATIONS_EMAIL_FROM, the "from address" you want your outgoing notification emails to use.
  • EZTASKMANAGER_NOTIFICATIONS_EMAIL_RECIPIENTS, a list of strings representing the recipients of the notifications.

The demo tutorial (RQ)

Following this tutorial, it will be possible to install, configure and use eztaskmanager for a simple demo django project running in developer mode, with the RQ engine.

Clone the project from github onto your hard disk:

    git clone https://github.com/openpolis/django-eztaskmanager
    cd django-eztaskmanager

There is a basic Django project under the demoproject directory, set to use eztaskmanager.

    demoproject/
    ├── demoproject/
    │   ├── __init__.py
    │   └── asgi.py
    │   ├── settings.py
    │   ├── test_settings.py
    │   ├── urls.py
    │   └── wsgi.py
    ├── manage.py
    ├── static/
    └── docker-compose-local.yml

Try the demo project

As a pre-requisite, a Redis server should be up and running on the default port 6379. Follow the instructions_, or if you use docker_, just run docker compose -f docker-compose-local.yml.

Enter the demoproject directory, then create and activate the virtual environments:

    $ cd demoproject
    $ mkdir -p venv
    $ python3 -m venv venv
    $ source venv/bin/activate

Install eztaskmanager, this will install all needed dependencies (django, redis, django-rq, rq-scheduler,...):

    (venv) $ pip install django-eztaskmanager

Then execute this commands to setup the server in development mode, the rq worker and the scheduler:

    (venv) $ python manage.py migrate  # create tables in the DB (default sqlite will do)
    (venv) $ python manage.py createsuperuser # take note of username and password for login
    (venv) $ python manage.py collectcommands --excludecore  # collect basic commands from the eztaskmanager package
    (venv) $ python manage.py runserver  # django app server on port 8000
    (venv) $ python manage.py rqworker  # rq worker to execute enqueued tasks
    (venv) $ python manage.py rqscheduler --verbosity=3  # rq scheduler to enqueue periodic tasks

Visit http://127.0.0.1:8000/admin/

Development and Testing

Running Tests

The project uses Django's test framework. Tests are located in eztaskmanager/tests/.

To run the test suite:

# Install development dependencies with Poetry
poetry install

# Run all tests
export PYTHONPATH="${PYTHONPATH}:$(pwd)"
poetry run python demoproject/manage.py test --verbosity=2

# Run specific test module
poetry run python demoproject/manage.py test eztaskmanager.tests.test_services

# Run tests with coverage
poetry run coverage run demoproject/manage.py test
poetry run coverage report

Code Quality

# Format code with black
poetry run black eztaskmanager/

# Run flake8 linting
poetry run flake8 eztaskmanager/

# Type checking with mypy
poetry run mypy eztaskmanager/

Django eztaskmanager is an application to manage common django management tasks asynchronously, via the Django admin interface, using Redis Queue.

Copyright (c) 2024 Guglielmo Celata (django-eztaskmanager)
Copyright (C) 2019-2020 Gabriele Giaccari, Gabriele Lucci, Guglielmo Celata, Paolo Melchiorre (django-uwsgi-taskmanager)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

Metadata

Release files for django-eztaskmanager 0.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-eztaskmanager 0.5.3
File Size Uploaded
django_eztaskmanager-0.5.3.tar.gz 165.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-eztaskmanager 0.5.3
File Interpreter ABI Platform
django_eztaskmanager-0.5.3-py3-none-any.whl Python 3 none any Details

Total release size: 344.0 kB

Release files / django_eztaskmanager-0.5.3.tar.gz

Download URL django_eztaskmanager-0.5.3.tar.gz
Size 165.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a6dbd918fd14857b9e53a09c7aa4df930df58153eb18e75bb964d648c7a3c96a
BLAKE2b-256 checksum
How to use checksums
3607672917a8eb893034b97b173129e5ecf8e757b39479e3aca0947ff4557613
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.14.7 Linux/6.17.0-1022-azure

Release files / django_eztaskmanager-0.5.3-py3-none-any.whl

Download URL django_eztaskmanager-0.5.3-py3-none-any.whl
Size 178.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4d5c6a79dfddb9918f9b1fdd3cd54b75a53846e5520268166c9b04e13e62d2a
BLAKE2b-256 checksum
How to use checksums
9cfff26c8561b3df6946f8e6e7e1d679924d155f6bd63fee775d641cc20d3663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.14.7 Linux/6.17.0-1022-azure

Release history Release notifications | RSS feed

This release

0.5.3 This release

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page