From ee1e732776fff16e9204c167ac84f34f09d3b202 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 22 May 2014 16:44:48 -0400 Subject: [PATCH] Close connection before and after executing periodic OCR task, to avoid stale DB connection remaining open. Ref: Issue #4 --- apps/ocr/tasks.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/ocr/tasks.py b/apps/ocr/tasks.py index 84d2c956d2..0e69e13bb2 100644 --- a/apps/ocr/tasks.py +++ b/apps/ocr/tasks.py @@ -5,6 +5,7 @@ import platform import logging from django.db.models import Q +from django import db from job_processor.api import process_job from lock_manager import Lock, LockError @@ -48,6 +49,8 @@ def task_process_queue_document(queue_document_id): def task_process_document_queues(): + # Make sure this task get a fresh connection to the database + db.close_connection() logger.debug('executed') # TODO: reset_orphans() q_pending = Q(state=QUEUEDOCUMENT_STATE_PENDING) @@ -74,3 +77,6 @@ def task_process_document_queues(): logger.debug('already processing maximum') else: logger.debug('nothing to process') + + # Close the database explicitly or else Django keeps it open + db.close_connection()