diff --git a/apps/converter/backends/python/base.py b/apps/converter/backends/python/base.py index cd2492bc65..e4affcb7fe 100644 --- a/apps/converter/backends/python/base.py +++ b/apps/converter/backends/python/base.py @@ -44,7 +44,7 @@ class ConverterClass(ConverterBase): try: while 1: - im.seek(im.tell()+1) + im.seek(im.tell() + 1) page_count += 1 # do something to im except EOFError: diff --git a/apps/job_processor/__init__.py b/apps/job_processor/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/job_processor/api.py b/apps/job_processor/api.py new file mode 100644 index 0000000000..eee19321b1 --- /dev/null +++ b/apps/job_processor/api.py @@ -0,0 +1,16 @@ +from celery.decorators import task, periodic_task +from celery.task.control import inspect + +from job_processor.conf.settings import BACKEND + + +@task +def celery_task(func, *args, **kwargs): + return func(*args, **kwargs) + + +def process_job(func, *args, **kwargs): + if BACKEND == 'celery': + return celery_task.delay(func, *args, **kwargs) + elif BACKEND is None: + return func(*args, **kwargs) diff --git a/apps/job_processor/conf/__init__.py b/apps/job_processor/conf/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/job_processor/conf/settings.py b/apps/job_processor/conf/settings.py new file mode 100644 index 0000000000..0d3b2fe9ea --- /dev/null +++ b/apps/job_processor/conf/settings.py @@ -0,0 +1,12 @@ +"""Configuration options for the job_processing app""" +from django.utils.translation import ugettext_lazy as _ + +from smart_settings.api import register_settings + +register_settings( + namespace=u'job_processor', + module=u'job_processor.conf.settings', + settings=[ + {'name': u'BACKEND', 'global_name': u'JOB_PROCESSING_BACKEND', 'default': None, 'description': _('Specified which job processing library to use, option are: None and celery.')}, + ] +) diff --git a/apps/job_processor/models.py b/apps/job_processor/models.py new file mode 100644 index 0000000000..71a8362390 --- /dev/null +++ b/apps/job_processor/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/apps/job_processor/tests.py b/apps/job_processor/tests.py new file mode 100644 index 0000000000..2247054b35 --- /dev/null +++ b/apps/job_processor/tests.py @@ -0,0 +1,23 @@ +""" +This file demonstrates two different styles of tests (one doctest and one +unittest). These will both pass when you run "manage.py test". + +Replace these with more appropriate tests for your application. +""" + +from django.test import TestCase + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.failUnlessEqual(1 + 1, 2) + +__test__ = {"doctest": """ +Another way to test that 1 + 1 is equal to 2. + +>>> 1 + 1 == 2 +True +"""} + diff --git a/apps/job_processor/views.py b/apps/job_processor/views.py new file mode 100644 index 0000000000..60f00ef0ef --- /dev/null +++ b/apps/job_processor/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/apps/ocr/tasks.py b/apps/ocr/tasks.py index 4da8c4eaf0..cceb77f034 100644 --- a/apps/ocr/tasks.py +++ b/apps/ocr/tasks.py @@ -7,8 +7,7 @@ from django.db.models import Q from django.utils.translation import ugettext as _ from django.core.cache import get_cache -from celery.decorators import task, periodic_task -from celery.task.control import inspect +from job_processor.api import process_job from ocr.api import do_document_ocr from ocr.literals import QUEUEDOCUMENT_STATE_PENDING, \ @@ -46,7 +45,6 @@ else: release_lock = lambda lock_id: True -#@task def task_process_queue_document(queue_document_id): lock_id = u'%s-lock-%d' % (u'task_process_queue_document', queue_document_id) if acquire_lock(lock_id): @@ -112,6 +110,7 @@ def task_process_document_queues(): if oldest_queued_document_qs: oldest_queued_document = oldest_queued_document_qs.order_by('datetime_submitted')[0] #task_process_queue_document.delay(oldest_queued_document.pk) - task_process_queue_document(oldest_queued_document.pk) + #task_process_queue_document(oldest_queued_document.pk) + process_job(task_process_queue_document, oldest_queued_document.pk) except Exception, e: print 'DocumentQueueWatcher exception: %s' % e diff --git a/settings.py b/settings.py index 11f05f2b14..4713ef3bbf 100644 --- a/settings.py +++ b/settings.py @@ -152,6 +152,7 @@ INSTALLED_APPS = ( 'sources', 'mimetype', 'scheduler', + 'job_processor', ) TEMPLATE_CONTEXT_PROCESSORS = (