django-background-tasks

raw JSON →
1.2.8 verified Fri May 01 auth: no python maintenance

Database backed asynchronous task queue for Django. Version 1.2.8. Release cadence: irregular, last release 2020.

pip install django-background-tasks
error ImportError: No module named 'background_task'
cause Missing 'background_task' in INSTALLED_APPS or not installed.
fix
Add 'background_task' to INSTALLED_APPS and run migrations.
error django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'task_params' used in key specification without a key length")
cause MySQL does not allow indexing TEXT columns without a prefix length.
fix
Upgrade to version 1.1.12+ which limits indexed field length to 190 characters.
gotcha The decorator-based task registration must be called at module import time; tasks defined inside functions or conditionally may not be registered.
fix Place @background_task decorator on top-level functions.
deprecated Removed log options from management command; use Django LOGGING setting.
fix Configure logging in settings.py, not via command-line options.

Define a task using the decorator and run the worker.

# models.py
def print_hello():
    from background_task import background_task
    @background_task(schedule=10)
    def hello(name):
        print("Hello %s" % name)
    hello("World", schedule=10)

# run: python manage.py process_tasks