From cef48da78963eeeb88bc1788c84feac8ec9a1ed7 Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Thu, 24 Sep 2015 15:41:32 +0200 Subject: [PATCH] removes root imports for django 1.9 Updated docs to promote submodule imports --- README.rst | 6 +++--- django_q/__init__.py | 19 ++++++++++++------- django_q/tests/test_cluster.py | 8 +++++--- django_q/tests/test_monitor.py | 3 ++- docs/conf.py | 2 +- docs/examples.rst | 13 +++++++------ docs/install.rst | 6 +++--- docs/schedules.rst | 8 +++++--- docs/tasks.rst | 13 +++++++------ setup.py | 2 +- 10 files changed, 46 insertions(+), 34 deletions(-) diff --git a/README.rst b/README.rst index c73c417..b6ebb92 100644 --- a/README.rst +++ b/README.rst @@ -113,7 +113,7 @@ Use `async` from your code to quickly offload tasks: .. code:: python - from django_q import async, result + from django_q.tasks import async, result # create the task async('math.copysign', 2, -2) @@ -149,9 +149,8 @@ Admin page or directly from your code: .. code:: python - from django_q import Schedule, schedule - # Use the schedule function + from django_q.tasks import schedule schedule('math.copysign', 2, -2, @@ -159,6 +158,7 @@ Admin page or directly from your code: schedule_type=Schedule.DAILY) # Or create the object directly + from django_q.models import Schedule Schedule.objects.create(func='math.copysign', hook='hooks.print_result', diff --git a/django_q/__init__.py b/django_q/__init__.py index b41f8c5..5b6e561 100644 --- a/django_q/__init__.py +++ b/django_q/__init__.py @@ -1,15 +1,20 @@ import os import sys +from django import get_version myPath = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, myPath) -from .tasks import async, schedule, result, result_group, fetch, fetch_group, count_group, delete_group, queue_size -from .models import Task, Schedule, Success, Failure -from .cluster import Cluster -from .status import Stat -from .brokers import get_broker - -VERSION = (0, 7, 3) +VERSION = (0, 7, 4) default_app_config = 'django_q.apps.DjangoQConfig' + +# root imports will slowly be deprecated. +# please import from the relevant sub modules +if get_version().split('.')[1][0] != '9': + from .tasks import async, schedule, result, result_group, fetch, fetch_group, count_group, delete_group, queue_size + from .models import Task, Schedule, Success, Failure + from .cluster import Cluster + from .status import Stat + from .brokers import get_broker + diff --git a/django_q/tests/test_cluster.py b/django_q/tests/test_cluster.py index 5f9c927..067fa65 100644 --- a/django_q/tests/test_cluster.py +++ b/django_q/tests/test_cluster.py @@ -2,8 +2,8 @@ import sys from multiprocessing import Queue, Event, Value import threading from time import sleep - import os + import pytest myPath = os.path.dirname(os.path.abspath(__file__)) @@ -226,8 +226,10 @@ def test_async(broker, admin_user): assert result_j.group_count(failures=True) == 0 assert delete_group('test_j') == 1 assert result_j.group_delete() == 0 - assert delete_group('test_j', tasks=True) is None - assert result_j.group_delete(tasks=True) is None + deleted_group = delete_group('test_j', tasks=True) + assert deleted_group is None or deleted_group[0] == 0 # Django 1.9 + deleted_group = result_j.group_delete(tasks=True) + assert delete_group is None or deleted_group[0] == 0 # Django 1.9 # task k should not have been saved assert fetch(k) is None assert fetch(k, 100) is None diff --git a/django_q/tests/test_monitor.py b/django_q/tests/test_monitor.py index 2c73723..61a5326 100644 --- a/django_q/tests/test_monitor.py +++ b/django_q/tests/test_monitor.py @@ -1,6 +1,7 @@ import pytest -from django_q import async, get_broker +from django_q.tasks import async +from django_q.brokers import get_broker from django_q.cluster import Cluster from django_q.monitor import monitor, info from django_q.status import Stat diff --git a/docs/conf.py b/docs/conf.py index 3f8cbb9..64d8346 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -72,7 +72,7 @@ author = 'Ilan Steemers' # The short X.Y version. version = '0.7' # The full version, including alpha/beta/rc tags. -release = '0.7.3' +release = '0.7.4' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/examples.rst b/docs/examples.rst index 9783d73..e785e2c 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -11,7 +11,8 @@ Sending an email can take a while so why not queue it: # Welcome mail with follow up example from datetime import timedelta from django.utils import timezone - from django_q import async, schedule, Schedule + from django_q.tasks import async, schedule + from django_q.models import Schedule def welcome_mail(user): @@ -49,7 +50,7 @@ A good place to use async tasks are Django's model signals. You don't want to de from django.contrib.auth.models import User from django.db.models.signals import pre_save from django.dispatch import receiver - from django_q import async + from django_q.tasks import async # set up the pre_save signal for our user @receiver(pre_save, sender=User) @@ -102,7 +103,7 @@ In this example the user requests a report and we let the cluster do the generat .. code-block:: python # Report generation with hook example - from django_q import async + from django_q.tasks import async # views.py # user requests a report. @@ -114,7 +115,7 @@ In this example the user requests a report and we let the cluster do the generat .. code-block:: python # tasks.py - from django_q import async + from django_q.tasks import async # report generator def create_html_report(user): @@ -150,7 +151,7 @@ here's an example of how you can have Django Q take care of your indexes in real from .models import Document from django.db.models.signals import post_save from django.dispatch import receiver - from django_q import async + from django_q.tasks import async # hook up the post save handler @receiver(post_save, sender=Document) @@ -187,7 +188,7 @@ Adapted from `Sebastian Raschka's blog ` provides Django Q with an alternative way of determining the number of CPU's on your system * CPU affinity is provided by :ref:`psutil` which at this time does not support this feature on OSX. The code however is aware of this and will fake the CPU affinity assignment in the logs without actually assigning it. This way you can still develop with this setting. @@ -116,7 +116,7 @@ Django We strive to be compatible with last two major version of Django. At the moment this means we support the 1.7.10 and 1.8.4 releases. Once version 1.9 is out , support for Django 1.7 will be deprecated. -This means than newer releases of Django Q might still work, but are no longer targeted for testing. +This will mean that newer releases of Django Q might still work, but are no longer targeted for testing. diff --git a/docs/schedules.rst b/docs/schedules.rst index 65171be..7710364 100644 --- a/docs/schedules.rst +++ b/docs/schedules.rst @@ -10,15 +10,17 @@ You can manage them through the :ref:`admin_page` or directly from your code wit .. code:: python - from django_q import Schedule, schedule - # Use the schedule wrapper + from django_q.tasks import schedule + schedule('math.copysign', 2, -2, hook='hooks.print_result', schedule_type=Schedule.DAILY) # Or create the object directly + from django_q.models import Schedule + Schedule.objects.create(func='math.copysign', hook='hooks.print_result', args='2,-2', @@ -65,7 +67,7 @@ If you want to schedule regular Django management commands, you can use the :mod return management.call_command('clearsessions') # now you can schedule it to run every hour - from django_q import schedule + from django_q.tasks import schedule schedule('tasks.clear_sessions_command', schedule_type='H') diff --git a/docs/tasks.rst b/docs/tasks.rst index ebcc576..094913d 100644 --- a/docs/tasks.rst +++ b/docs/tasks.rst @@ -11,7 +11,7 @@ Use :func:`async` from your code to quickly offload tasks to the :class:`Cluster .. code:: python - from django_q import async, result + from django_q.tasks import async, result # create the task async('math.copysign', 2, -2) @@ -88,7 +88,7 @@ You can group together results by passing :func:`async` the optional ``group`` k .. code-block:: python # result group example - from django_q import async, result_group + from django_q.tasks import async, result_group for i in range(4): async('math.modf', i, group='modf') @@ -107,7 +107,7 @@ Instead of :func:`result_group` you can also use :func:`fetch_group` to return a .. code-block:: python # fetch group example - from django_q import fetch_group, count_group, result_group + from django_q.tasks import fetch_group, count_group, result_group # count the number of failures failure_count = count_group('modf', failures=True) @@ -137,7 +137,7 @@ You can also access group functions from a task result instance: .. code-block:: python - from django_q import fetch + from django_q.tasks import fetch task = fetch('winter-speaker-alpha-ceiling') if task.group_count() > 100: @@ -151,7 +151,7 @@ Synchronous testing :func:`async` can be instructed to execute a task immediately by setting the optional keyword ``sync=True``. The task will then be injected straight into a worker and the result saved by a monitor instance:: - from django_q import async, fetch + from django_q.tasks import async, fetch # create a synchronous task task_id = async('my.buggy.code', sync=True) @@ -179,7 +179,8 @@ When you are making individual calls to :func:`async` a lot though, it can help .. code:: python # broker connection economy example - from django_q import async, get_broker + from django_q.tasks import async + from django_q.brokers import get_broker broker = get_broker() for i in range(50): diff --git a/setup.py b/setup.py index 72cc558..6e9f978 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ class PyTest(Command): setup( name='django-q', - version='0.7.3', + version='0.7.4', author='Ilan Steemers', author_email='koed0@gmail.com', keywords='django distributed task queue worker redis disque ironmq sqs orm multiprocessing',