django-task


Namedjango-task JSON
Version 2.0.7 PyPI version JSON
download
home_pagehttps://github.com/morlandi/django-task
SummaryA Django app to run new background tasks from either admin or cron, and inspect task history from admin; based on django-rq
upload_time2024-05-03 21:07:20
maintainerNone
docs_urlNone
authorMario Orlandi
requires_pythonNone
licenseMIT
keywords django-task
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            ===========
django-task
===========

.. image:: https://badge.fury.io/py/django-task.svg
    :target: https://badge.fury.io/py/django-task

.. image:: https://travis-ci.org/morlandi/django-task.svg?branch=master
    :target: https://travis-ci.org/morlandi/django-task

.. image:: https://codecov.io/gh/morlandi/django-task/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/morlandi/django-task

A Django app to run new background tasks from either admin or cron, and inspect task history from admin

.. contents::

.. sectnum::

Quickstart
----------

1) **Install Django Task**:

.. code-block:: bash

    pip install django-task

2) **Add it to your `INSTALLED_APPS`**:

.. code-block:: python

    INSTALLED_APPS = (
        ...
        'django_rq',  # optional (not needed when using TaskThreaded)
        'django_task',
        ...
    )

3) **Add Django Task's URL patterns**:

.. code-block:: python

    urlpatterns = [
        ...
        path('django_task/', include('django_task.urls', namespace='django_task')),
        ...
    ]

4) **Configure Redis and RQ in settings.py** (not needed when using TaskThreaded):

.. code-block:: python

    #REDIS_URL = 'redis://localhost:6379/0'
    redis_host = os.environ.get('REDIS_HOST', 'localhost')
    redis_port = 6379
    REDIS_URL = 'redis://%s:%d/0' % (redis_host, redis_port)

    CACHES = {
        'default': {
            'BACKEND': 'redis_cache.RedisCache',
            'LOCATION': REDIS_URL
        },
    }

    #
    # RQ config
    #

    RQ_PREFIX = "myproject_"
    QUEUE_DEFAULT = RQ_PREFIX + 'default'
    QUEUE_HIGH = RQ_PREFIX + 'high'
    QUEUE_LOW = RQ_PREFIX + 'low'

    RQ_QUEUES = {
        QUEUE_DEFAULT: {
            'URL': REDIS_URL,
            #'PASSWORD': 'some-password',
            'DEFAULT_TIMEOUT': 360,
        },
        QUEUE_HIGH: {
            'URL': REDIS_URL,
            'DEFAULT_TIMEOUT': 500,
        },
        QUEUE_LOW: {
            'URL': REDIS_URL,
            #'ASYNC': False,
        },
    }

Note: if you plan to install many instances of the project on the same server,
for each instance use a specific value for `RQ_PREFIX`; for example:

.. code-block:: python

    INSTANCE_PREFIX = "myproject_"
    try:
        from project.settings.instance_prefix import *
    except Exception as e:
        pass
    RQ_PREFIX = INSTANCE_PREFIX

    QUEUE_DEFAULT = RQ_PREFIX + '_default'
    QUEUE_LOW = RQ_PREFIX + '_low'
    QUEUE_HIGH = RQ_PREFIX + '_high'

    ...

5) **Customize django-task specific settings (optional)**:

.. code-block:: python

    RQ_SHOW_ADMIN_LINK = False
    DJANGOTASK_LOG_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', 'protected', 'tasklog'))
    DJANGOTASK_ALWAYS_EAGER = False
    DJANGOTASK_JOB_TRACE_ENABLED = False
    DJANGOTASK_REJECT_IF_NO_WORKER_ACTIVE_FOR_QUEUE = True

6) **Optionally, revoke pending tasks at startapp**;

file `main/apps.py`:

.. code-block:: python

    class MainConfig(AppConfig):

        ...

        def ready(self):

            ...
            try:
                from django_task.utils import revoke_pending_tasks
                revoke_pending_tasks()
            except Exception as e:
                print(e)

Features
--------

**Purposes**

- create async tasks either programmatically or from admin
- monitor async tasks from admin
- log all tasks in the database for later inspection
- optionally save task-specific logs in a TextField and/or in a FileField

**Details**

1. each specific task is described by a Model derived from either models.TaskRQ or models.TaskThreaded, which
   is responsible for:

   - selecting the name for the consumer queue among available queues (TaskRQ only)
   - collecting and saving all parameters required by the associated job
   - running the specific job asyncronously

2. a new job can be run either:

   - creating a Task from the Django admin
   - creating a Task from code, then calling Task.run()

3. job execution workflow:

   - job execution is triggered by task.run(is_async)
   - job will receive the task.id, and retrieve paramerts from it
   - on start, job will update task status to 'STARTED' and save job.id for reference
   - during execution, the job can update the progress indicator
   - on completion, task status is finally updated to either 'SUCCESS' or 'FAILURE'
   - See example.jobs.count_beans for an example


Screenshots
-----------

.. image:: example/etc/screenshot_001.png

.. image:: example/etc/screenshot_002.png


App settings
------------

DJANGOTASK_LOG_ROOT
    Path for log files.

    Default: None

    Example: os.path.abspath(os.path.join(BASE_DIR, '..', 'protected', 'tasklog'))

DJANGOTASK_ALWAYS_EAGER
    When True, all task are execute syncronously (useful for debugging and unit testing).

    Default: False

DJANGOTASK_JOB_TRACE_ENABLED
    Enables low level tracing in Job.run() - for debugging challenging race conditions

    Default: False

DJANGOTASK_REJECT_IF_NO_WORKER_ACTIVE_FOR_QUEUE
    Rejects task if not active worker is available for the specific task queue
    when task.run() is called

    Default: False

REDIS_URL
    Redis server to connect to

    Default: 'redis://localhost:6379/0'


Verbosity levels
----------------

The `verbosity level` controls the logging level as follows:

=============== ===================
verbosity       log level
--------------- -------------------
0               no log
1               logging.WARNING
2               logging.INFO
3               logging.DEBUG
=============== ===================

and can be set by the derived class:

.. code:: python

    class MyTask(TaskRQ):
        ...
        DEFAULT_VERBOSITY = 2
        ...

or you can set it on a "per task" basis by adding to the model
a `task_verbosity` field as follows:

.. code:: python

    task_verbosity = models.PositiveIntegerField(null=False, blank=False, default=2,
        choices=((0,'0'), (1,'1'), (2,'2'), (3,'3')),
    )

In case, when creating a management command you might want to preserve the default
value provided by the class, or override it if and only if the verbosity option
has been set by the user:

.. code:: python

    import sys

    def handle(self, *args, **options):

        if '-v' in sys.argv or '--verbosity'in sys.argv:
            options['task_verbosity'] = options['verbosity']

        self.run_task(MyTask, **options)


Running Tests
-------------

Does the code actually work?

Running the unit tests from your project::

    python manage.py test -v 2 django_task --settings=django_task.tests.settings

Running the unit tests from your local fork::

    source <YOURVIRTUALENV>/bin/activate
    (myenv) $ pip install tox
    (myenv) $ tox

or::

    python ./runtests.py

or::

    coverage run --source='.' runtests.py
    coverage report


Threaded vs RQ-based tasks
--------------------------

The original implementation is based on django-rq and RQ (a Redis based Python queuing library).

On some occasions, using a background queue may be overkill or even inappropriate:
if you need to run many short I/O-bound background tasks concurrently, the serialization
provided by the queue, while limiting the usage of resources, would cause eccessive delay.

Starting from version 2.0.0, in those cases you can use TaskThreaded instead of TaskRQ;
this way, each background task will run in it's own thread.

**MIGRATING FROM django-task 1.5.1 to 2.0.0**

- derive your queue-based tasks from TaskRQ instead of Task
- or use TaskThreaded
- get_jobclass() overridable replaces get_jobfunc()

Support Job class
-----------------

Starting from version 0.3.0, some conveniences have been added:

- The @job decorator for job functions is no more required, as Task.run() now
  uses queue.enqueue() instead of jobfunc.delay(), and retrieves the queue
  name directly from the Task itself

- each Task can set it's own TASK_TIMEOUT value (expressed in seconds),
  that when provided overrides the default queue timeout

- a new Job class has been provided to share suggested common logic before and
  after jobfunc execution; you can either override `run()` to implement a custom logic,
  or (in most cases) just supply your own `execute()` method, and optionally
  override `on_complete()` to execute cleanup actions after job completion;

example:

.. code :: python

    class CountBeansJob(Job):

        @staticmethod
        def execute(job, task):
            num_beans = task.num_beans
            for i in range(0, num_beans):
                time.sleep(0.01)
                task.set_progress((i + 1) * 100 / num_beans, step=10)

        @staticmethod
        def on_complete(job, task):
            print('task "%s" completed with: %s' % (str(task.id), task.status))
            # An more realistic example from a real project ...
            # if task.status != 'SUCCESS' or task.error_counter > 0:
            #    task.alarm = BaseTask.ALARM_STATUS_ALARMED
            #    task.save(update_fields=['alarm', ])


**Execute**

Run consumer:

.. code:: bash

    python manage.py runserver


Run worker(s):

.. code:: bash

    python manage.py rqworker low high default
    python manage.py rqworker low high default
    ...

**Sample Task**

.. code:: python

    from django.db import models
    from django.conf import settings
    from django_task.models import TaskRQ


    class SendEmailTask(TaskRQ):

        sender = models.CharField(max_length=256, null=False, blank=False)
        recipients = models.TextField(null=False, blank=False,
            help_text='put addresses in separate rows')
        subject = models.CharField(max_length=256, null=False, blank=False)
        message = models.TextField(null=False, blank=True)

        TASK_QUEUE = settings.QUEUE_LOW
        TASK_TIMEOUT = 60
        LOG_TO_FIELD = True
        LOG_TO_FILE = False
        DEFAULT_VERBOSITY = 2

        @staticmethod
        def get_jobclass():
            from .jobs import SendEmailJob
            return SendEmailJob

When using **LOG_TO_FILE = True**, you might want to add a cleanup handler to
remove the log file when the corresponding record is deleted::

    import os
    from django.dispatch import receiver

    @receiver(models.signals.post_delete, sender=ImportaCantieriTask)
    def on_sendemailtask_delete_cleanup(sender, instance, **kwargs):
        """
        Autodelete logfile on Task delete
        """
        logfile = instance._logfile()
        if os.path.isfile(logfile):
            os.remove(logfile)

**Sample Job**

.. code:: python

    import redis
    import logging
    import traceback
    from django.conf import settings
    from .models import SendEmailTask
    from django_task.job import Job


    class SendEmailJob(Job):

        @staticmethod
        def execute(job, task):
            recipient_list = task.recipients.split()
            sender = task.sender.strip()
            subject = task.subject.strip()
            message = task.message
            from django.core.mail import send_mail
            send_mail(subject, message, sender, recipient_list)


**Sample management command**

.. code:: python

    from django_task.task_command import TaskCommand
    from django.contrib.auth import get_user_model

    class Command(TaskCommand):

        def add_arguments(self, parser):
            super(Command, self).add_arguments(parser)
            parser.add_argument('sender')
            parser.add_argument('subject')
            parser.add_argument('message')
            parser.add_argument('-r', '--recipients', nargs='*')
            parser.add_argument('-u', '--user', type=str, help="Specify username for 'created_by' task field")

        def handle(self, *args, **options):
            from tasks.models import SendEmailTask

            # transform the list of recipents into text
            # (one line for each recipient)
            options['recipients'] = '\n'.join(options['recipients']) if options['recipients'] is not None else ''

            # format multiline message
            options['message'] = options['message'].replace('\\n', '\n')

            if 'user' in options:
                created_by = get_user_model().objects.get(username=options['user'])
            else:
                created_by = None

            self.run_task(SendEmailTask, created_by=created_by, **options)

**Deferred Task retrieval to avoid job vs. Task race condition**

An helper Task.get_task_from_id() classmethod is supplied to retrieve Task object
from task_id safely.

*Task queues create a new type of race condition. Why ?
Because message queues are fast !
How fast ?
Faster than databases.*

See:

https://speakerdeck.com/siloraptor/django-tasty-salad-dos-and-donts-using-celery

A similar generic helper is available for Job-derived needs::

    django_task.utils.get_model_from_id(model_cls, id, timeout=1000, retry_count=10)


**Howto schedule jobs with cron**

Call management command 'count_beans', which in turn executes the required job.

For example::

    SHELL=/bin/bash
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

    0 * * * *  {{username}}    timeout 55m {{django.pythonpath}}/python {{django.website_home}}/manage.py count_beans 1000 >> {{django.logto}}/cron.log 2>&1

A base class TaskCommand has been provided to simplify the creation of any specific
task-related management commad;

a derived management command is only responsible for:

- defining suitable command-line parameters
- selecting the specific Task class and job function

for example:

.. code:: python

    from django_task.task_command import TaskCommand


    class Command(TaskCommand):

        def add_arguments(self, parser):
            super(Command, self).add_arguments(parser)
            parser.add_argument('num_beans', type=int)

        def handle(self, *args, **options):
            from tasks.models import CountBeansTask
            self.run_task(CountBeansTask, **options)


Javascript helpers
------------------

A few utility views have been supplied for interacting with tasks from javascript.

tasks_info_api
..............

Retrieve informations about a list of existing tasks

Sample usage:

.. code:: javascript

    var tasks = [{
        id: 'c50bf040-a886-4aed-bf41-4ae794db0941',
        model: 'tasks.devicetesttask'
    }, {
        id: 'e567c651-c8d5-4dc7-9cbf-860988f55022',
        model: 'tasks.devicetesttask'
    }];

    $.ajax({
        url: '/django_task/info/',
        data: JSON.stringify(tasks),
        cache: false,
        type: 'post',
        dataType: 'json',
        headers: {'X-CSRFToken': getCookie('csrftoken')}
    }).done(function(data) {
        console.log('data: %o', data);
    });

Result::

    [
      {
        "id": "c50bf040-a886-4aed-bf41-4ae794db0941",
        "created_on": "2018-10-11T17:45:14.399491+00:00",
        "created_on_display": "10/11/2018 19:45:14",
        "created_by": "4f943f0b-f5a3-4fd8-bb2e-451d2be107e2",
        "started_on": null,
        "started_on_display": "",
        "completed_on": null,
        "completed_on_display": "",
        "job_id": "",
        "status": "PENDING",
        "status_display": "<div class=\"task_status\" data-task-model=\"tasks.devicetesttask\" data-task-id=\"c50bf040-a886-4aed-bf41-4ae794db0941\" data-task-status=\"PENDING\" data-task-complete=\"0\">PENDING</div>",
        "log_link_display": "",
        "failure_reason": "",
        "progress": null,
        "progress_display": "-",
        "completed": false,
        "duration": null,
        "duration_display": "",
        "extra_fields": {
        }
      },
      ...
    ]

task_add_api
............

Create and run a new task based on specified parameters

Expected parameters:

- 'task-model' = "<app_name>.<model_name>"
- ... task parameters ...

Returns the id of the new task.

Sample usage:

.. code:: javascript

    function exportAcquisition(object_id) {
        if (confirm('Do you want to export data ?')) {

            var url = '/django_task/add/';
            var data = JSON.stringify({
                'task-model': 'tasks.exportdatatask',
                'source': 'backend.acquisition',
                'object_id': object_id
            });

            $.ajax({
                type: 'POST',
                url: url,
                data: data,
                cache: false,
                crossDomain: true,
                dataType: 'json',
                headers: {'X-CSRFToken': getCookie('csrftoken')}
            }).done(function(data) {
                console.log('data: %o', data);
                alert('New task created: "' + data.task_id + '"');
            }).fail(function(jqXHR, textStatus, errorThrown) {
                console.log('ERROR: ' + jqXHR.responseText);
                alert(errorThrown);
            });
        }
        return;
    }

task_run_api
............

Schedule execution of specified task.

Returns job.id or throws error (400).

Parameters:

- app_label
- model_name
- pk
- is_async (0 or 1, default=1)

Sample usage:

.. code:: javascript

    var task_id = 'c50bf040-a886-4aed-bf41-4ae794db0941';

    $.ajax({
        url: sprintf('/django_task/tasks/devicetesttask/%s/run/', task_id),
        cache: false,
        type: 'get'
    }).done(function(data) {
        console.log('data: %o', data);
    }).fail(function(jqXHR, textStatus, errorThrown) {
        display_server_error(jqXHR.responseText);
    });


Updating the tasks listing dynamically in the frontend
------------------------------------------------------

The list of Tasks in the admin changelist_view is automatically updated to refresh
the progess and status of each running Task.

You can obtain the same result in the frontend by calling the **DjangoTask.update_tasks()**
javascript helper, provided you're listing the tasks in an HTML table with a similar layout.

The simplest way to do it is to use the **render_task_column_names_as_table_row**
and **render_task_as_table_row** template tags.

Example:

.. code:: html

    {% load i18n django_task_tags %}

    {% if not export_data_tasks %}
        <div>{% trans 'No recent jobs available' %}</div>
    {% else %}
        <table id="export_data_tasks" class="table table-striped">
            {% with excluded='created_by,created_on,job_id,log_text,mode' %}
            <thead>
                <tr>
                    {{ export_data_tasks.0|render_task_column_names_as_table_row:excluded }}
                </tr>
            </thead>
            <tbody>
                {% for task in export_data_tasks %}
                <tr>
                    {{ task|render_task_as_table_row:excluded }}
                </tr>
                {% endfor %}
            </tbody>
        </table>
        {% endwith %}
    {% endif %}


    {% block extrajs %}
        {{ block.super }}
        <script type="text/javascript" src="{% static 'js/django_task.js' %}"></script>
        <script>
            $(document).ready(function() {
                DjangoTask.update_tasks(1000, '#export_data_tasks');
            });
        </script>
    {% endblock extrajs %}

For each fieldname included in the table rows, **render_task_as_table_row** will
check if a FIELDNAME_display() method is available in the Task model, and in case
will use it for rendering the field value; otherwise, the field value will be simply
converted into a string.

If the specific derived Task model defines some additional fields (unknown to the base Task model)
which need to be updated regularly by **DjangoTask.update_tasks()**, include them as "extra_fields"
as follows:

.. code:: python

    def as_dict(self):
        data = super(ExportDataTask, self).as_dict()
        data['extra_fields'] = {
            'result_display': mark_safe(self.result_display())
        }
        return data

.. image:: example/etc/screenshot_003.png

Example Project for django-task
-------------------------------

As example project is provided as a convenience feature to allow potential users
to try the app straight from the app repo without having to create a django project.

Please follow the instructions detailed in file `example/README.rst <example/README.rst>`_.


Credits
-------

References:

- `A simple app that provides django integration for RQ (Redis Queue) <https://github.com/ui/django-rq>`_
- `Asynchronous tasks in django with django-rq <https://spapas.github.io/2015/01/27/async-tasks-with-django-rq/>`_
- `django-rq redux: advanced techniques and tools <https://spapas.github.io/2015/09/01/django-rq-redux/>`_
- `Benchmark: Shared vs. Dedicated Redis Instances <https://redislabs.com/blog/benchmark-shared-vs-dedicated-redis-instances/>`_
- `Django tasty salad - DOs and DON'Ts using Celery by Roberto Rosario <https://speakerdeck.com/siloraptor/django-tasty-salad-dos-and-donts-using-celery>`_
- `Can Django do multi-thread works? <https://stackoverflow.com/questions/17601698/can-django-do-multi-thread-works#53327191>`_





=======
History
=======

2.0.7
-----
* Fix issue with jQuery is not defined; thanks to Alexkiro (https://github.com/alexkiro)

2.0.6
-----
* fix duration_display()

2.0.5
-----
* TaskCommand.run_task() now returns the ID of the created Task

2.0.4
-----
* TaskCommand.run_task() now returns the created Task

2.0.3
-----
* Prepare for Django 4.0

2.0.2
-----
* TaskCommand now uses "-v" / "--verbosity" command line options to set task_verbosity

2.0.1
-----
* optional "per task" verbosity level
* POSSIBLE INCOMPATIBLE CHANGE: verbosity levels has been shifted (set as documented in the README)

2.0.0
-----
* Split Task model into TaskBase + TaskRQ
* Implement TaskThreaded (experimental)
* Drop Django1 and Python2.7
* cleanup

1.5.1
-----
* Moved required imports inside Job.run() so it can be more easily replicated for any needed customization
* Simpler queues settings
* Revamped unit testing
* Cleanup

1.5.0
-----
* Support for updating the tasks listing dynamically in the frontend
* Example provided for task_add_api() javascript helper
* POSSIBLY INCOMPATIBLE CHANGE: duration and duration_display are now methods rather then properties
* it traslation for UI messages

1.4.7
-----
* Added optional "created_by" parameter to TaskCommand utility

1.4.6
-----
* replace namespace "django.jQuery" with more generic "jQuery" in js helpers
* update example project
* unit tests added to "tasks" app in example project

1.4.5
-----
* Quickstart revised in README

1.4.4
-----
* Task.get_logger() is now publicly available

1.4.3
-----
* restore compatibility with Django 1.11; upgrade rq and django-rq requirements

1.4.2
-----
* tasks_info_api() optimized to use a single query

1.4.1
-----
* Cleanup: remove redundant REJECTED status

1.4.0
-----
* Update requirements (Django >= 2.0, django-rq>=2.0)

1.3.10
------
* Use exceptions.TaskError class when raising specific exceptions

v1.3.9
------
* removed forgotten pdb.set_trace() in revoke_pending_tasks()

v1.3.8
------
* cleanup

v1.3.7
------
* cleanup

v1.3.6
------
* log queue name

v1.3.5
------
* Readme updated

v1.3.4
------
* javascript helper views
* fix Task.set_progress(0)

v1.3.3
------
* make sure fields are unique in TaskAdmin fieldsets

v1.3.1
------
* unit tests verified with Python 2.7/3.6/3.7 and Django 1.10/2.0

v1.3.0
------
* cleanup
* classify as production/stable

v1.2.5
------
* Tested with Django 2.0 and Python 3.7
* Rename `async` to `is_async` to support Python 3.7
* DJANGOTASK_REJECT_IF_NO_WORKER_ACTIVE_FOR_QUEUE app setting added
* example cleanup

v1.2.4
------
* API to create and run task via ajax

v1.2.3
------
* TaskAdmin: postpone autorun to response_add() to have M2M task parameters (if any) ready
* Task.clone() supports M2M parameters

v1.2.2
------
* property to change verbosity dinamically

v1.2.1
------
* util revoke_pending_tasks() added

v1.2.0
------
* DJANGOTASK_JOB_TRACE_ENABLED setting added to enable low level tracing in Job.run()
* Added missing import in utils.py

v1.1.3
------
* cleanup: remove get_child() method being Task an abstract class
* fix: skip Task model (being abstract) in dump_all_tasks and delete_all_tasks management commands
* generic get_model_from_id() helper
* Job.on_complete() callback

v1.1.2
------
* provide list of pending and completed task status

v1.1.0
------
* INCOMPATIBLE CHANGE: Make model Task abstract for better listing performances
* redundant migrations removed
* convert request.body to string for Python3
* pretty print task params in log when task completes

v0.3.8
------
* return verbose name as description

v0.3.7
------
* description added to Task model

v0.3.6
------
* More fixes

v0.3.5
------
* log to field fix

v0.3.4
------
* log quickview + view

v0.3.3
------
* Optionally log to either file or text field
* Management commands to dump and delete all tasks

v0.3.2
------
* search by task.id and task.job_id

v0.3.1
------
* Keep track of task mode (sync or async)

v0.3.0
------
* new class Job provided to share task-related logic among job funcs

v0.2.0
------
* fixes for django 2.x

v0.1.15
-------
* hack for  prepopulated_fields

v0.1.14
-------
* css fix

v0.1.13
-------
* minor fixes

v0.1.12
-------
* Deferred Task retrieval to avoid job vs. Task race condition
* Improved Readme

v0.1.11
-------
* superuser can view all tasks, while other users have access to their own tasks only
* js fix

v0.1.10
-------
* prevent task.failure_reason overflow

v0.1.9
------
* app settings

v0.1.8
------
* always start job from task.run() to prevent any possible race condition
* task.run(async) can now accept async=False

v0.1.7
------
* javascript: use POST to retrieve tasks state for UI update to prevent URL length limit exceed

v0.1.6
------
* Improved ui for TaskAdmin
* Fix unicode literals for Python3

v0.1.5
------
* fixes for Django 1.10
* send_email management command example added

v0.1.4
------
* Fix OneToOneRel import for Django < 1.9

v0.1.3
------
* Polymorphic behaviour or Task.get_child() restored

v0.1.2
------
* TaskCommand.run_task() renamed as TaskCommand.run_job()
* New TaskCommand.run_task() creates a Task, then runs it;
  this guarantees that something is traced even when background job will fail



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/morlandi/django-task",
    "name": "django-task",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "django-task",
    "author": "Mario Orlandi",
    "author_email": "morlandi@brainstorm.it",
    "download_url": null,
    "platform": null,
    "description": "===========\ndjango-task\n===========\n\n.. image:: https://badge.fury.io/py/django-task.svg\n    :target: https://badge.fury.io/py/django-task\n\n.. image:: https://travis-ci.org/morlandi/django-task.svg?branch=master\n    :target: https://travis-ci.org/morlandi/django-task\n\n.. image:: https://codecov.io/gh/morlandi/django-task/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/morlandi/django-task\n\nA Django app to run new background tasks from either admin or cron, and inspect task history from admin\n\n.. contents::\n\n.. sectnum::\n\nQuickstart\n----------\n\n1) **Install Django Task**:\n\n.. code-block:: bash\n\n    pip install django-task\n\n2) **Add it to your `INSTALLED_APPS`**:\n\n.. code-block:: python\n\n    INSTALLED_APPS = (\n        ...\n        'django_rq',  # optional (not needed when using TaskThreaded)\n        'django_task',\n        ...\n    )\n\n3) **Add Django Task's URL patterns**:\n\n.. code-block:: python\n\n    urlpatterns = [\n        ...\n        path('django_task/', include('django_task.urls', namespace='django_task')),\n        ...\n    ]\n\n4) **Configure Redis and RQ in settings.py** (not needed when using TaskThreaded):\n\n.. code-block:: python\n\n    #REDIS_URL = 'redis://localhost:6379/0'\n    redis_host = os.environ.get('REDIS_HOST', 'localhost')\n    redis_port = 6379\n    REDIS_URL = 'redis://%s:%d/0' % (redis_host, redis_port)\n\n    CACHES = {\n        'default': {\n            'BACKEND': 'redis_cache.RedisCache',\n            'LOCATION': REDIS_URL\n        },\n    }\n\n    #\n    # RQ config\n    #\n\n    RQ_PREFIX = \"myproject_\"\n    QUEUE_DEFAULT = RQ_PREFIX + 'default'\n    QUEUE_HIGH = RQ_PREFIX + 'high'\n    QUEUE_LOW = RQ_PREFIX + 'low'\n\n    RQ_QUEUES = {\n        QUEUE_DEFAULT: {\n            'URL': REDIS_URL,\n            #'PASSWORD': 'some-password',\n            'DEFAULT_TIMEOUT': 360,\n        },\n        QUEUE_HIGH: {\n            'URL': REDIS_URL,\n            'DEFAULT_TIMEOUT': 500,\n        },\n        QUEUE_LOW: {\n            'URL': REDIS_URL,\n            #'ASYNC': False,\n        },\n    }\n\nNote: if you plan to install many instances of the project on the same server,\nfor each instance use a specific value for `RQ_PREFIX`; for example:\n\n.. code-block:: python\n\n    INSTANCE_PREFIX = \"myproject_\"\n    try:\n        from project.settings.instance_prefix import *\n    except Exception as e:\n        pass\n    RQ_PREFIX = INSTANCE_PREFIX\n\n    QUEUE_DEFAULT = RQ_PREFIX + '_default'\n    QUEUE_LOW = RQ_PREFIX + '_low'\n    QUEUE_HIGH = RQ_PREFIX + '_high'\n\n    ...\n\n5) **Customize django-task specific settings (optional)**:\n\n.. code-block:: python\n\n    RQ_SHOW_ADMIN_LINK = False\n    DJANGOTASK_LOG_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', 'protected', 'tasklog'))\n    DJANGOTASK_ALWAYS_EAGER = False\n    DJANGOTASK_JOB_TRACE_ENABLED = False\n    DJANGOTASK_REJECT_IF_NO_WORKER_ACTIVE_FOR_QUEUE = True\n\n6) **Optionally, revoke pending tasks at startapp**;\n\nfile `main/apps.py`:\n\n.. code-block:: python\n\n    class MainConfig(AppConfig):\n\n        ...\n\n        def ready(self):\n\n            ...\n            try:\n                from django_task.utils import revoke_pending_tasks\n                revoke_pending_tasks()\n            except Exception as e:\n                print(e)\n\nFeatures\n--------\n\n**Purposes**\n\n- create async tasks either programmatically or from admin\n- monitor async tasks from admin\n- log all tasks in the database for later inspection\n- optionally save task-specific logs in a TextField and/or in a FileField\n\n**Details**\n\n1. each specific task is described by a Model derived from either models.TaskRQ or models.TaskThreaded, which\n   is responsible for:\n\n   - selecting the name for the consumer queue among available queues (TaskRQ only)\n   - collecting and saving all parameters required by the associated job\n   - running the specific job asyncronously\n\n2. a new job can be run either:\n\n   - creating a Task from the Django admin\n   - creating a Task from code, then calling Task.run()\n\n3. job execution workflow:\n\n   - job execution is triggered by task.run(is_async)\n   - job will receive the task.id, and retrieve paramerts from it\n   - on start, job will update task status to 'STARTED' and save job.id for reference\n   - during execution, the job can update the progress indicator\n   - on completion, task status is finally updated to either 'SUCCESS' or 'FAILURE'\n   - See example.jobs.count_beans for an example\n\n\nScreenshots\n-----------\n\n.. image:: example/etc/screenshot_001.png\n\n.. image:: example/etc/screenshot_002.png\n\n\nApp settings\n------------\n\nDJANGOTASK_LOG_ROOT\n    Path for log files.\n\n    Default: None\n\n    Example: os.path.abspath(os.path.join(BASE_DIR, '..', 'protected', 'tasklog'))\n\nDJANGOTASK_ALWAYS_EAGER\n    When True, all task are execute syncronously (useful for debugging and unit testing).\n\n    Default: False\n\nDJANGOTASK_JOB_TRACE_ENABLED\n    Enables low level tracing in Job.run() - for debugging challenging race conditions\n\n    Default: False\n\nDJANGOTASK_REJECT_IF_NO_WORKER_ACTIVE_FOR_QUEUE\n    Rejects task if not active worker is available for the specific task queue\n    when task.run() is called\n\n    Default: False\n\nREDIS_URL\n    Redis server to connect to\n\n    Default: 'redis://localhost:6379/0'\n\n\nVerbosity levels\n----------------\n\nThe `verbosity level` controls the logging level as follows:\n\n=============== ===================\nverbosity       log level\n--------------- -------------------\n0               no log\n1               logging.WARNING\n2               logging.INFO\n3               logging.DEBUG\n=============== ===================\n\nand can be set by the derived class:\n\n.. code:: python\n\n    class MyTask(TaskRQ):\n        ...\n        DEFAULT_VERBOSITY = 2\n        ...\n\nor you can set it on a \"per task\" basis by adding to the model\na `task_verbosity` field as follows:\n\n.. code:: python\n\n    task_verbosity = models.PositiveIntegerField(null=False, blank=False, default=2,\n        choices=((0,'0'), (1,'1'), (2,'2'), (3,'3')),\n    )\n\nIn case, when creating a management command you might want to preserve the default\nvalue provided by the class, or override it if and only if the verbosity option\nhas been set by the user:\n\n.. code:: python\n\n    import sys\n\n    def handle(self, *args, **options):\n\n        if '-v' in sys.argv or '--verbosity'in sys.argv:\n            options['task_verbosity'] = options['verbosity']\n\n        self.run_task(MyTask, **options)\n\n\nRunning Tests\n-------------\n\nDoes the code actually work?\n\nRunning the unit tests from your project::\n\n    python manage.py test -v 2 django_task --settings=django_task.tests.settings\n\nRunning the unit tests from your local fork::\n\n    source <YOURVIRTUALENV>/bin/activate\n    (myenv) $ pip install tox\n    (myenv) $ tox\n\nor::\n\n    python ./runtests.py\n\nor::\n\n    coverage run --source='.' runtests.py\n    coverage report\n\n\nThreaded vs RQ-based tasks\n--------------------------\n\nThe original implementation is based on django-rq and RQ (a Redis based Python queuing library).\n\nOn some occasions, using a background queue may be overkill or even inappropriate:\nif you need to run many short I/O-bound background tasks concurrently, the serialization\nprovided by the queue, while limiting the usage of resources, would cause eccessive delay.\n\nStarting from version 2.0.0, in those cases you can use TaskThreaded instead of TaskRQ;\nthis way, each background task will run in it's own thread.\n\n**MIGRATING FROM django-task 1.5.1 to 2.0.0**\n\n- derive your queue-based tasks from TaskRQ instead of Task\n- or use TaskThreaded\n- get_jobclass() overridable replaces get_jobfunc()\n\nSupport Job class\n-----------------\n\nStarting from version 0.3.0, some conveniences have been added:\n\n- The @job decorator for job functions is no more required, as Task.run() now\n  uses queue.enqueue() instead of jobfunc.delay(), and retrieves the queue\n  name directly from the Task itself\n\n- each Task can set it's own TASK_TIMEOUT value (expressed in seconds),\n  that when provided overrides the default queue timeout\n\n- a new Job class has been provided to share suggested common logic before and\n  after jobfunc execution; you can either override `run()` to implement a custom logic,\n  or (in most cases) just supply your own `execute()` method, and optionally\n  override `on_complete()` to execute cleanup actions after job completion;\n\nexample:\n\n.. code :: python\n\n    class CountBeansJob(Job):\n\n        @staticmethod\n        def execute(job, task):\n            num_beans = task.num_beans\n            for i in range(0, num_beans):\n                time.sleep(0.01)\n                task.set_progress((i + 1) * 100 / num_beans, step=10)\n\n        @staticmethod\n        def on_complete(job, task):\n            print('task \"%s\" completed with: %s' % (str(task.id), task.status))\n            # An more realistic example from a real project ...\n            # if task.status != 'SUCCESS' or task.error_counter > 0:\n            #    task.alarm = BaseTask.ALARM_STATUS_ALARMED\n            #    task.save(update_fields=['alarm', ])\n\n\n**Execute**\n\nRun consumer:\n\n.. code:: bash\n\n    python manage.py runserver\n\n\nRun worker(s):\n\n.. code:: bash\n\n    python manage.py rqworker low high default\n    python manage.py rqworker low high default\n    ...\n\n**Sample Task**\n\n.. code:: python\n\n    from django.db import models\n    from django.conf import settings\n    from django_task.models import TaskRQ\n\n\n    class SendEmailTask(TaskRQ):\n\n        sender = models.CharField(max_length=256, null=False, blank=False)\n        recipients = models.TextField(null=False, blank=False,\n            help_text='put addresses in separate rows')\n        subject = models.CharField(max_length=256, null=False, blank=False)\n        message = models.TextField(null=False, blank=True)\n\n        TASK_QUEUE = settings.QUEUE_LOW\n        TASK_TIMEOUT = 60\n        LOG_TO_FIELD = True\n        LOG_TO_FILE = False\n        DEFAULT_VERBOSITY = 2\n\n        @staticmethod\n        def get_jobclass():\n            from .jobs import SendEmailJob\n            return SendEmailJob\n\nWhen using **LOG_TO_FILE = True**, you might want to add a cleanup handler to\nremove the log file when the corresponding record is deleted::\n\n    import os\n    from django.dispatch import receiver\n\n    @receiver(models.signals.post_delete, sender=ImportaCantieriTask)\n    def on_sendemailtask_delete_cleanup(sender, instance, **kwargs):\n        \"\"\"\n        Autodelete logfile on Task delete\n        \"\"\"\n        logfile = instance._logfile()\n        if os.path.isfile(logfile):\n            os.remove(logfile)\n\n**Sample Job**\n\n.. code:: python\n\n    import redis\n    import logging\n    import traceback\n    from django.conf import settings\n    from .models import SendEmailTask\n    from django_task.job import Job\n\n\n    class SendEmailJob(Job):\n\n        @staticmethod\n        def execute(job, task):\n            recipient_list = task.recipients.split()\n            sender = task.sender.strip()\n            subject = task.subject.strip()\n            message = task.message\n            from django.core.mail import send_mail\n            send_mail(subject, message, sender, recipient_list)\n\n\n**Sample management command**\n\n.. code:: python\n\n    from django_task.task_command import TaskCommand\n    from django.contrib.auth import get_user_model\n\n    class Command(TaskCommand):\n\n        def add_arguments(self, parser):\n            super(Command, self).add_arguments(parser)\n            parser.add_argument('sender')\n            parser.add_argument('subject')\n            parser.add_argument('message')\n            parser.add_argument('-r', '--recipients', nargs='*')\n            parser.add_argument('-u', '--user', type=str, help=\"Specify username for 'created_by' task field\")\n\n        def handle(self, *args, **options):\n            from tasks.models import SendEmailTask\n\n            # transform the list of recipents into text\n            # (one line for each recipient)\n            options['recipients'] = '\\n'.join(options['recipients']) if options['recipients'] is not None else ''\n\n            # format multiline message\n            options['message'] = options['message'].replace('\\\\n', '\\n')\n\n            if 'user' in options:\n                created_by = get_user_model().objects.get(username=options['user'])\n            else:\n                created_by = None\n\n            self.run_task(SendEmailTask, created_by=created_by, **options)\n\n**Deferred Task retrieval to avoid job vs. Task race condition**\n\nAn helper Task.get_task_from_id() classmethod is supplied to retrieve Task object\nfrom task_id safely.\n\n*Task queues create a new type of race condition. Why ?\nBecause message queues are fast !\nHow fast ?\nFaster than databases.*\n\nSee:\n\nhttps://speakerdeck.com/siloraptor/django-tasty-salad-dos-and-donts-using-celery\n\nA similar generic helper is available for Job-derived needs::\n\n    django_task.utils.get_model_from_id(model_cls, id, timeout=1000, retry_count=10)\n\n\n**Howto schedule jobs with cron**\n\nCall management command 'count_beans', which in turn executes the required job.\n\nFor example::\n\n    SHELL=/bin/bash\n    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n\n    0 * * * *  {{username}}    timeout 55m {{django.pythonpath}}/python {{django.website_home}}/manage.py count_beans 1000 >> {{django.logto}}/cron.log 2>&1\n\nA base class TaskCommand has been provided to simplify the creation of any specific\ntask-related management commad;\n\na derived management command is only responsible for:\n\n- defining suitable command-line parameters\n- selecting the specific Task class and job function\n\nfor example:\n\n.. code:: python\n\n    from django_task.task_command import TaskCommand\n\n\n    class Command(TaskCommand):\n\n        def add_arguments(self, parser):\n            super(Command, self).add_arguments(parser)\n            parser.add_argument('num_beans', type=int)\n\n        def handle(self, *args, **options):\n            from tasks.models import CountBeansTask\n            self.run_task(CountBeansTask, **options)\n\n\nJavascript helpers\n------------------\n\nA few utility views have been supplied for interacting with tasks from javascript.\n\ntasks_info_api\n..............\n\nRetrieve informations about a list of existing tasks\n\nSample usage:\n\n.. code:: javascript\n\n    var tasks = [{\n        id: 'c50bf040-a886-4aed-bf41-4ae794db0941',\n        model: 'tasks.devicetesttask'\n    }, {\n        id: 'e567c651-c8d5-4dc7-9cbf-860988f55022',\n        model: 'tasks.devicetesttask'\n    }];\n\n    $.ajax({\n        url: '/django_task/info/',\n        data: JSON.stringify(tasks),\n        cache: false,\n        type: 'post',\n        dataType: 'json',\n        headers: {'X-CSRFToken': getCookie('csrftoken')}\n    }).done(function(data) {\n        console.log('data: %o', data);\n    });\n\nResult::\n\n    [\n      {\n        \"id\": \"c50bf040-a886-4aed-bf41-4ae794db0941\",\n        \"created_on\": \"2018-10-11T17:45:14.399491+00:00\",\n        \"created_on_display\": \"10/11/2018 19:45:14\",\n        \"created_by\": \"4f943f0b-f5a3-4fd8-bb2e-451d2be107e2\",\n        \"started_on\": null,\n        \"started_on_display\": \"\",\n        \"completed_on\": null,\n        \"completed_on_display\": \"\",\n        \"job_id\": \"\",\n        \"status\": \"PENDING\",\n        \"status_display\": \"<div class=\\\"task_status\\\" data-task-model=\\\"tasks.devicetesttask\\\" data-task-id=\\\"c50bf040-a886-4aed-bf41-4ae794db0941\\\" data-task-status=\\\"PENDING\\\" data-task-complete=\\\"0\\\">PENDING</div>\",\n        \"log_link_display\": \"\",\n        \"failure_reason\": \"\",\n        \"progress\": null,\n        \"progress_display\": \"-\",\n        \"completed\": false,\n        \"duration\": null,\n        \"duration_display\": \"\",\n        \"extra_fields\": {\n        }\n      },\n      ...\n    ]\n\ntask_add_api\n............\n\nCreate and run a new task based on specified parameters\n\nExpected parameters:\n\n- 'task-model' = \"<app_name>.<model_name>\"\n- ... task parameters ...\n\nReturns the id of the new task.\n\nSample usage:\n\n.. code:: javascript\n\n    function exportAcquisition(object_id) {\n        if (confirm('Do you want to export data ?')) {\n\n            var url = '/django_task/add/';\n            var data = JSON.stringify({\n                'task-model': 'tasks.exportdatatask',\n                'source': 'backend.acquisition',\n                'object_id': object_id\n            });\n\n            $.ajax({\n                type: 'POST',\n                url: url,\n                data: data,\n                cache: false,\n                crossDomain: true,\n                dataType: 'json',\n                headers: {'X-CSRFToken': getCookie('csrftoken')}\n            }).done(function(data) {\n                console.log('data: %o', data);\n                alert('New task created: \"' + data.task_id + '\"');\n            }).fail(function(jqXHR, textStatus, errorThrown) {\n                console.log('ERROR: ' + jqXHR.responseText);\n                alert(errorThrown);\n            });\n        }\n        return;\n    }\n\ntask_run_api\n............\n\nSchedule execution of specified task.\n\nReturns job.id or throws error (400).\n\nParameters:\n\n- app_label\n- model_name\n- pk\n- is_async (0 or 1, default=1)\n\nSample usage:\n\n.. code:: javascript\n\n    var task_id = 'c50bf040-a886-4aed-bf41-4ae794db0941';\n\n    $.ajax({\n        url: sprintf('/django_task/tasks/devicetesttask/%s/run/', task_id),\n        cache: false,\n        type: 'get'\n    }).done(function(data) {\n        console.log('data: %o', data);\n    }).fail(function(jqXHR, textStatus, errorThrown) {\n        display_server_error(jqXHR.responseText);\n    });\n\n\nUpdating the tasks listing dynamically in the frontend\n------------------------------------------------------\n\nThe list of Tasks in the admin changelist_view is automatically updated to refresh\nthe progess and status of each running Task.\n\nYou can obtain the same result in the frontend by calling the **DjangoTask.update_tasks()**\njavascript helper, provided you're listing the tasks in an HTML table with a similar layout.\n\nThe simplest way to do it is to use the **render_task_column_names_as_table_row**\nand **render_task_as_table_row** template tags.\n\nExample:\n\n.. code:: html\n\n    {% load i18n django_task_tags %}\n\n    {% if not export_data_tasks %}\n        <div>{% trans 'No recent jobs available' %}</div>\n    {% else %}\n        <table id=\"export_data_tasks\" class=\"table table-striped\">\n            {% with excluded='created_by,created_on,job_id,log_text,mode' %}\n            <thead>\n                <tr>\n                    {{ export_data_tasks.0|render_task_column_names_as_table_row:excluded }}\n                </tr>\n            </thead>\n            <tbody>\n                {% for task in export_data_tasks %}\n                <tr>\n                    {{ task|render_task_as_table_row:excluded }}\n                </tr>\n                {% endfor %}\n            </tbody>\n        </table>\n        {% endwith %}\n    {% endif %}\n\n\n    {% block extrajs %}\n        {{ block.super }}\n        <script type=\"text/javascript\" src=\"{% static 'js/django_task.js' %}\"></script>\n        <script>\n            $(document).ready(function() {\n                DjangoTask.update_tasks(1000, '#export_data_tasks');\n            });\n        </script>\n    {% endblock extrajs %}\n\nFor each fieldname included in the table rows, **render_task_as_table_row** will\ncheck if a FIELDNAME_display() method is available in the Task model, and in case\nwill use it for rendering the field value; otherwise, the field value will be simply\nconverted into a string.\n\nIf the specific derived Task model defines some additional fields (unknown to the base Task model)\nwhich need to be updated regularly by **DjangoTask.update_tasks()**, include them as \"extra_fields\"\nas follows:\n\n.. code:: python\n\n    def as_dict(self):\n        data = super(ExportDataTask, self).as_dict()\n        data['extra_fields'] = {\n            'result_display': mark_safe(self.result_display())\n        }\n        return data\n\n.. image:: example/etc/screenshot_003.png\n\nExample Project for django-task\n-------------------------------\n\nAs example project is provided as a convenience feature to allow potential users\nto try the app straight from the app repo without having to create a django project.\n\nPlease follow the instructions detailed in file `example/README.rst <example/README.rst>`_.\n\n\nCredits\n-------\n\nReferences:\n\n- `A simple app that provides django integration for RQ (Redis Queue) <https://github.com/ui/django-rq>`_\n- `Asynchronous tasks in django with django-rq <https://spapas.github.io/2015/01/27/async-tasks-with-django-rq/>`_\n- `django-rq redux: advanced techniques and tools <https://spapas.github.io/2015/09/01/django-rq-redux/>`_\n- `Benchmark: Shared vs. Dedicated Redis Instances <https://redislabs.com/blog/benchmark-shared-vs-dedicated-redis-instances/>`_\n- `Django tasty salad - DOs and DON'Ts using Celery by Roberto Rosario <https://speakerdeck.com/siloraptor/django-tasty-salad-dos-and-donts-using-celery>`_\n- `Can Django do multi-thread works? <https://stackoverflow.com/questions/17601698/can-django-do-multi-thread-works#53327191>`_\n\n\n\n\n\n=======\nHistory\n=======\n\n2.0.7\n-----\n* Fix issue with jQuery is not defined; thanks to Alexkiro (https://github.com/alexkiro)\n\n2.0.6\n-----\n* fix duration_display()\n\n2.0.5\n-----\n* TaskCommand.run_task() now returns the ID of the created Task\n\n2.0.4\n-----\n* TaskCommand.run_task() now returns the created Task\n\n2.0.3\n-----\n* Prepare for Django 4.0\n\n2.0.2\n-----\n* TaskCommand now uses \"-v\" / \"--verbosity\" command line options to set task_verbosity\n\n2.0.1\n-----\n* optional \"per task\" verbosity level\n* POSSIBLE INCOMPATIBLE CHANGE: verbosity levels has been shifted (set as documented in the README)\n\n2.0.0\n-----\n* Split Task model into TaskBase + TaskRQ\n* Implement TaskThreaded (experimental)\n* Drop Django1 and Python2.7\n* cleanup\n\n1.5.1\n-----\n* Moved required imports inside Job.run() so it can be more easily replicated for any needed customization\n* Simpler queues settings\n* Revamped unit testing\n* Cleanup\n\n1.5.0\n-----\n* Support for updating the tasks listing dynamically in the frontend\n* Example provided for task_add_api() javascript helper\n* POSSIBLY INCOMPATIBLE CHANGE: duration and duration_display are now methods rather then properties\n* it traslation for UI messages\n\n1.4.7\n-----\n* Added optional \"created_by\" parameter to TaskCommand utility\n\n1.4.6\n-----\n* replace namespace \"django.jQuery\" with more generic \"jQuery\" in js helpers\n* update example project\n* unit tests added to \"tasks\" app in example project\n\n1.4.5\n-----\n* Quickstart revised in README\n\n1.4.4\n-----\n* Task.get_logger() is now publicly available\n\n1.4.3\n-----\n* restore compatibility with Django 1.11; upgrade rq and django-rq requirements\n\n1.4.2\n-----\n* tasks_info_api() optimized to use a single query\n\n1.4.1\n-----\n* Cleanup: remove redundant REJECTED status\n\n1.4.0\n-----\n* Update requirements (Django >= 2.0, django-rq>=2.0)\n\n1.3.10\n------\n* Use exceptions.TaskError class when raising specific exceptions\n\nv1.3.9\n------\n* removed forgotten pdb.set_trace() in revoke_pending_tasks()\n\nv1.3.8\n------\n* cleanup\n\nv1.3.7\n------\n* cleanup\n\nv1.3.6\n------\n* log queue name\n\nv1.3.5\n------\n* Readme updated\n\nv1.3.4\n------\n* javascript helper views\n* fix Task.set_progress(0)\n\nv1.3.3\n------\n* make sure fields are unique in TaskAdmin fieldsets\n\nv1.3.1\n------\n* unit tests verified with Python 2.7/3.6/3.7 and Django 1.10/2.0\n\nv1.3.0\n------\n* cleanup\n* classify as production/stable\n\nv1.2.5\n------\n* Tested with Django 2.0 and Python 3.7\n* Rename `async` to `is_async` to support Python 3.7\n* DJANGOTASK_REJECT_IF_NO_WORKER_ACTIVE_FOR_QUEUE app setting added\n* example cleanup\n\nv1.2.4\n------\n* API to create and run task via ajax\n\nv1.2.3\n------\n* TaskAdmin: postpone autorun to response_add() to have M2M task parameters (if any) ready\n* Task.clone() supports M2M parameters\n\nv1.2.2\n------\n* property to change verbosity dinamically\n\nv1.2.1\n------\n* util revoke_pending_tasks() added\n\nv1.2.0\n------\n* DJANGOTASK_JOB_TRACE_ENABLED setting added to enable low level tracing in Job.run()\n* Added missing import in utils.py\n\nv1.1.3\n------\n* cleanup: remove get_child() method being Task an abstract class\n* fix: skip Task model (being abstract) in dump_all_tasks and delete_all_tasks management commands\n* generic get_model_from_id() helper\n* Job.on_complete() callback\n\nv1.1.2\n------\n* provide list of pending and completed task status\n\nv1.1.0\n------\n* INCOMPATIBLE CHANGE: Make model Task abstract for better listing performances\n* redundant migrations removed\n* convert request.body to string for Python3\n* pretty print task params in log when task completes\n\nv0.3.8\n------\n* return verbose name as description\n\nv0.3.7\n------\n* description added to Task model\n\nv0.3.6\n------\n* More fixes\n\nv0.3.5\n------\n* log to field fix\n\nv0.3.4\n------\n* log quickview + view\n\nv0.3.3\n------\n* Optionally log to either file or text field\n* Management commands to dump and delete all tasks\n\nv0.3.2\n------\n* search by task.id and task.job_id\n\nv0.3.1\n------\n* Keep track of task mode (sync or async)\n\nv0.3.0\n------\n* new class Job provided to share task-related logic among job funcs\n\nv0.2.0\n------\n* fixes for django 2.x\n\nv0.1.15\n-------\n* hack for  prepopulated_fields\n\nv0.1.14\n-------\n* css fix\n\nv0.1.13\n-------\n* minor fixes\n\nv0.1.12\n-------\n* Deferred Task retrieval to avoid job vs. Task race condition\n* Improved Readme\n\nv0.1.11\n-------\n* superuser can view all tasks, while other users have access to their own tasks only\n* js fix\n\nv0.1.10\n-------\n* prevent task.failure_reason overflow\n\nv0.1.9\n------\n* app settings\n\nv0.1.8\n------\n* always start job from task.run() to prevent any possible race condition\n* task.run(async) can now accept async=False\n\nv0.1.7\n------\n* javascript: use POST to retrieve tasks state for UI update to prevent URL length limit exceed\n\nv0.1.6\n------\n* Improved ui for TaskAdmin\n* Fix unicode literals for Python3\n\nv0.1.5\n------\n* fixes for Django 1.10\n* send_email management command example added\n\nv0.1.4\n------\n* Fix OneToOneRel import for Django < 1.9\n\nv0.1.3\n------\n* Polymorphic behaviour or Task.get_child() restored\n\nv0.1.2\n------\n* TaskCommand.run_task() renamed as TaskCommand.run_job()\n* New TaskCommand.run_task() creates a Task, then runs it;\n  this guarantees that something is traced even when background job will fail\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Django app to run new background tasks from either admin or cron, and inspect task history from admin; based on django-rq",
    "version": "2.0.7",
    "project_urls": {
        "Homepage": "https://github.com/morlandi/django-task"
    },
    "split_keywords": [
        "django-task"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f9e011964001df87ee1141c2f86c4071aa28474285ff74652a8763aaea67d98c",
                "md5": "9f5744da52102cd4d656e99188c0efca",
                "sha256": "b306ce4c9d2b2e965b6b48c633984b862a0044824f273f10c09f24ec0e02930f"
            },
            "downloads": -1,
            "filename": "django_task-2.0.7-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9f5744da52102cd4d656e99188c0efca",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 43198,
            "upload_time": "2024-05-03T21:07:20",
            "upload_time_iso_8601": "2024-05-03T21:07:20.442110Z",
            "url": "https://files.pythonhosted.org/packages/f9/e0/11964001df87ee1141c2f86c4071aa28474285ff74652a8763aaea67d98c/django_task-2.0.7-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-03 21:07:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "morlandi",
    "github_project": "django-task",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "requirements": [],
    "tox": true,
    "lcname": "django-task"
}
        
Elapsed time: 0.79214s