From ebdcede59f2bd1e71e00e4b1449403fbaac9bd6d Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Sat, 23 Apr 2011 05:38:59 -0400 Subject: [PATCH] Made the queue processing interval configurable by means of a new setting: OCR_QUEUE_PROCESSING_INTERVAL --- apps/ocr/conf/settings.py | 1 + apps/ocr/tasks.py | 5 ++++- settings.py | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/ocr/conf/settings.py b/apps/ocr/conf/settings.py index 4ef84ea31d..3b421f1e62 100644 --- a/apps/ocr/conf/settings.py +++ b/apps/ocr/conf/settings.py @@ -7,3 +7,4 @@ REPLICATION_DELAY = getattr(settings, 'OCR_REPLICATION_DELAY', 10) # In seconds NODE_CONCURRENT_EXECUTION = getattr(settings, 'OCR_NODE_CONCURRENT_EXECUTION', 1) AUTOMATIC_OCR = getattr(settings, 'OCR_AUTOMATIC_OCR', False) PDFTOTEXT_PATH = getattr(settings, 'OCR_PDFTOTEXT_PATH', u'/usr/bin/pdftotext') +QUEUE_PROCESSING_INTERVAL = getattr(settings, 'OCR_QUEUE_PROCESSING_INTERVAL', 10) # In seconds diff --git a/apps/ocr/tasks.py b/apps/ocr/tasks.py index bb218d58ce..e69d816277 100644 --- a/apps/ocr/tasks.py +++ b/apps/ocr/tasks.py @@ -4,6 +4,7 @@ import time import random from django.db.models import Q +from django.utils.translation import ugettext as _ from celery.decorators import task, periodic_task @@ -14,6 +15,7 @@ from ocr.literals import QUEUEDOCUMENT_STATE_PENDING, \ from ocr.models import QueueDocument, DocumentQueue from ocr.conf.settings import NODE_CONCURRENT_EXECUTION from ocr.conf.settings import REPLICATION_DELAY +from ocr.conf.settings import QUEUE_PROCESSING_INTERVAL @task @@ -24,6 +26,7 @@ def task_process_queue_document(queue_document_id): return queue_document.state = QUEUEDOCUMENT_STATE_PROCESSING queue_document.node_name = platform.node() + queue_document.result = task_process_queue_document.request.id queue_document.save() try: do_document_ocr(queue_document.document) @@ -34,7 +37,7 @@ def task_process_queue_document(queue_document_id): queue_document.save() -@periodic_task(run_every=timedelta(seconds=15)) +@periodic_task(run_every=timedelta(seconds=QUEUE_PROCESSING_INTERVAL)) def task_process_document_queues(): #Introduce random 0 < t < 1 second delay to further reduce the #chance of a race condition diff --git a/settings.py b/settings.py index 9d3df9b589..ebb1a8987b 100644 --- a/settings.py +++ b/settings.py @@ -230,6 +230,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( #OCR_REPLICATION_DELAY = 10 #OCR_AUTOMATIC_OCR = False #OCR_PDFTOTEXT_PATH = u'/usr/bin/pdftotext' +#OCR_QUEUE_PROCESSING_INTERVAL = 10 # In seconds # Permissions #ROLES_DEFAULT_ROLES = []