Skip to content

Commit 0b8472f

Browse files
authored
Merge pull request #21 from dabapps/upgrade-django-versions
Upgrade Django
2 parents ce6543e + 4a06b2c commit 0b8472f

File tree

8 files changed

+35
-26
lines changed

8 files changed

+35
-26
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ sudo: false
33
python:
44
- '2.7'
55
- '3.4'
6+
- '3.6'
67
env:
7-
- DJANGO_VERSION=1.7
88
- DJANGO_VERSION=1.8
9+
- DJANGO_VERSION=1.9
10+
- DJANGO_VERSION=1.10
11+
- DJANGO_VERSION=1.11
912
install:
1013
- pip install -r test-requirements.txt
1114
- pip install -U django==$DJANGO_VERSION

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ Simple databased-backed job queue. Jobs are defined in your settings, and are pr
77

88
Asynchronous tasks are run via a *job queue*. This system is designed to support multi-step job workflows.
99

10-
**NOTE**: This module uses differing implementations of UUIDField on Django 1.7 and 1.8 - a Python 3 shimmed django-uuidfield version on 1.7, and the built-in implementation on Django 1.8 and above. The simplest way to upgrade it is to drop the existing
11-
`django_dbq_job` table, delete the migration from `django_migrations`, and then
12-
re-run `manage.py migrate`.
10+
Tested against Django 1.8, 1.9, 1.10, 1.11
1311

1412
## Getting Started
1513

django_dbq/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.0.1'
1+
__version__ = '1.2.0'

django_dbq/management/commands/create_job.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from django.conf import settings
22
from django.core.management.base import BaseCommand, CommandError
33
from django_dbq.models import Job
4-
from optparse import make_option
54
import json
65
import logging
76

@@ -14,12 +13,22 @@ class Command(BaseCommand):
1413
help = "Create a job"
1514
args = '<job_name>'
1615

17-
option_list = BaseCommand.option_list + (
18-
make_option('--workspace',
19-
help='JSON-formatted initial command workspace'),
20-
make_option('--queue_name',
21-
help='A specific queue to add this job to'),
22-
)
16+
def add_arguments(self, parser):
17+
parser.add_argument('args', nargs='+')
18+
parser.add_argument(
19+
'--workspace',
20+
action='store_true',
21+
dest='workspace',
22+
default=None,
23+
help="JSON-formatted initial commandworkspace."
24+
)
25+
parser.add_argument(
26+
'--queue_name',
27+
action='store_true',
28+
dest='queue_name',
29+
default=None,
30+
help="A specific queue to add this job to"
31+
)
2332

2433
def handle(self, *args, **options):
2534
if len(args) != 1:

django_dbq/management/commands/worker.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from django.db import transaction
22
from django.core.management.base import BaseCommand, CommandError
3-
from django.utils.module_loading import import_by_path
3+
from django.utils.module_loading import import_string
44
from django_dbq.models import Job
5-
from optparse import make_option
65
from simplesignals.process import WorkerProcessBase
76
from time import sleep
87
import logging
@@ -27,7 +26,7 @@ def process_job(queue_name):
2726
job.save()
2827

2928
try:
30-
task_function = import_by_path(job.next_task)
29+
task_function = import_string(job.next_task)
3130
task_function(job)
3231
job.update_next_task()
3332
if not job.next_task:
@@ -41,7 +40,7 @@ def process_job(queue_name):
4140
failure_hook_name = job.get_failure_hook_name()
4241
if failure_hook_name:
4342
logger.info("Running failure hook %s for job id=%s", failure_hook_name, job.pk)
44-
failure_hook_function = import_by_path(failure_hook_name)
43+
failure_hook_function = import_string(failure_hook_name)
4544
failure_hook_function(job, exception)
4645
else:
4746
logger.info("No failure hook for job id=%s", job.pk)
@@ -72,12 +71,14 @@ class Command(BaseCommand):
7271

7372
help = "Run a queue worker process"
7473

75-
option_list = BaseCommand.option_list + (
76-
make_option('--dry-run',
74+
def add_arguments(self, parser):
75+
parser.add_argument('queue_name', nargs='?', default='default', type=str)
76+
parser.add_argument(
77+
'--dry-run',
7778
action='store_true',
7879
dest='dry_run',
7980
default=False,
80-
help="Don't actually start the worker. Used for testing."),
81+
help="Don't actually start the worker. Used for testing."
8182
)
8283

8384
def handle(self, *args, **options):
@@ -87,7 +88,7 @@ def handle(self, *args, **options):
8788
if len(args) != 1:
8889
raise CommandError("Please supply a single queue job name")
8990

90-
queue_name = args[0]
91+
queue_name = options['queue_name']
9192

9293
self.stdout.write("Starting job worker for queue \"%s\"" % queue_name)
9394

django_dbq/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.db import models
2-
from django.utils.module_loading import import_by_path
2+
from django.utils.module_loading import import_string
33
from django_dbq.tasks import get_next_task_name, get_failure_hook_name, get_creation_hook_name
44
from jsonfield import JSONField
55
from model_utils import Choices
@@ -103,6 +103,5 @@ def run_creation_hook(self):
103103
creation_hook_name = self.get_creation_hook_name()
104104
if creation_hook_name:
105105
logger.info("Running creation hook %s for new job", creation_hook_name)
106-
creation_hook_function = import_by_path(creation_hook_name)
106+
creation_hook_function = import_string(creation_hook_name)
107107
creation_hook_function(self)
108-

django_dbq/tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from datetime import datetime, timedelta
22
from django.core.management import call_command, CommandError
3-
from django.core.urlresolvers import reverse
43
from django.test import TestCase
54
from django.test.utils import override_settings
65
from django_dbq.management.commands.worker import process_job
@@ -73,7 +72,7 @@ def test_worker_no_args(self):
7372

7473
def test_worker_with_queue_name(self):
7574
stdout = StringIO()
76-
call_command('worker', 'test_queue', dry_run=True, stdout=stdout)
75+
call_command('worker', queue_name='test_queue', dry_run=True, stdout=stdout)
7776
output = stdout.getvalue()
7877
self.assertTrue('test_queue' in output)
7978

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
-r requirements.txt
2-
pymysql==0.6.7
2+
pymysql==0.7.11

0 commit comments

Comments
 (0)