Skip to content

Commit

Permalink
Merge pull request #74 from Koed00/dev
Browse files Browse the repository at this point in the history
Removes root imports for Django 1.9
  • Loading branch information
Koed00 committed Sep 25, 2015
2 parents dd8ea03 + 3aa50bc commit ef6a604
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 37 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -149,16 +149,16 @@ 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,
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',
Expand Down
19 changes: 12 additions & 7 deletions django_q/__init__.py
Original file line number Diff line number Diff line change
@@ -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

8 changes: 5 additions & 3 deletions django_q/tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from multiprocessing import Queue, Event, Value
import threading
from time import sleep

import os

import pytest

myPath = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -227,8 +227,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 deleted_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
Expand Down
3 changes: 2 additions & 1 deletion django_q/tests/test_monitor.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
# 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.
Expand Down
13 changes: 7 additions & 6 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.



Expand Down
8 changes: 5 additions & 3 deletions docs/schedules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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')

Expand Down
13 changes: 7 additions & 6 deletions docs/tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#
arrow==0.6.0
blessed==1.9.5
boto3==1.1.3
botocore==1.2.4 # via boto3
boto3==1.1.4
botocore==1.2.5 # via boto3
django-picklefield==0.3.2
django-redis==4.2.0
docutils==0.12 # via botocore
Expand All @@ -16,7 +16,7 @@ futures==2.2.0 # via boto3
hiredis==0.2.0
iron-core==1.1.9 # via iron-mq
iron-mq==0.7
jmespath==0.7.1 # via boto3, botocore
jmespath==0.8.0 # via boto3, botocore
msgpack-python==0.4.6 # via django-redis
psutil==3.2.1
python-dateutil==2.4.2 # via arrow, botocore, iron-core
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run(self):

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',
Expand Down

0 comments on commit ef6a604

Please sign in to comment.