mirror of
https://github.com/django-q2/django-q2.git
synced 2026-09-15 13:37:56 +08:00
removes root imports for django 1.9
Updated docs to promote submodule imports
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 <http://sebastianraschka.com/Articles/201
|
||||
# Group example with Parzen-window estimation
|
||||
import numpy
|
||||
|
||||
from django_q import async, result_group,\
|
||||
from django_q.tasks import async, result_group,\
|
||||
count_group, delete_group
|
||||
|
||||
# the estimation function
|
||||
|
||||
@@ -79,9 +79,9 @@ Django Q is still a young project. If you do find any incompatibilities please s
|
||||
|
||||
OS X
|
||||
~~~~
|
||||
This should be completely compatible, except for the following known issues:
|
||||
Running Django Q on OS X should work fine, except for the following known issues:
|
||||
|
||||
* ``multiprocessing.Queue.qsize()`` is not supported. This leads to the monitor not reporting the internal queue size of clusters running under OS X.
|
||||
* :meth:`multiprocessing.Queue.qsize()` is not supported. This leads to the monitor not reporting the internal queue size of clusters running under OS X.
|
||||
* CPU count through :func:`multiprocessing.cpu_count()` does not work. Installing :ref:`psutil<psutil_package>` provides Django Q with an alternative way of determining the number of CPU's on your system
|
||||
* CPU affinity is provided by :ref:`psutil<psutil_package>` 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.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user