summaryrefslogtreecommitdiffstats
path: root/devel/management/commands
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2013-01-16 03:49:56 +0100
committerDan McGee <dan@archlinux.org>2013-01-16 03:49:56 +0100
commitaf32c23768c7537f19e0613525579208b4f44eb4 (patch)
treeb4738329c119e8e9987d8f12b4b4043a653417fb /devel/management/commands
parent0f6a0a1cd0011c8ad137a4b27d0b39a7e1129fb7 (diff)
downloadarchweb-af32c23768c7537f19e0613525579208b4f44eb4.tar.gz
archweb-af32c23768c7537f19e0613525579208b4f44eb4.tar.xz
Handle connection and transaction more properly in reporead
A few minor things are fixed here. One is PostgreSQL, and more specifically pgbouncer, don't like it when the connection is closed after psycopg2 has started an implicit transaction even for read-only queries. Ensure we call commit as our last database action in all cases. The other is related- Django in management commands doesn't ever call close on any database connection you may have been using, so PostgreSQL gets mad about this fact and logs a message saying such. Close the connection explicitly when we are done with it to play nice. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'devel/management/commands')
-rw-r--r--devel/management/commands/reporead.py1
-rw-r--r--devel/management/commands/reporead_inotify.py15
2 files changed, 10 insertions, 6 deletions
diff --git a/devel/management/commands/reporead.py b/devel/management/commands/reporead.py
index e00e54c..ab0efee 100644
--- a/devel/management/commands/reporead.py
+++ b/devel/management/commands/reporead.py
@@ -589,6 +589,7 @@ def read_repo(primary_arch, repo_file, options):
else:
db_update(arch, repo, packages_arches[arch], force)
logger.info('Finished database updates for %s.', repo_file)
+ connection.commit()
connection.close()
return 0
diff --git a/devel/management/commands/reporead_inotify.py b/devel/management/commands/reporead_inotify.py
index 04f6576..8c1e47b 100644
--- a/devel/management/commands/reporead_inotify.py
+++ b/devel/management/commands/reporead_inotify.py
@@ -23,7 +23,7 @@ import threading
import time
from django.core.management.base import BaseCommand, CommandError
-from django.db import connection
+from django.db import connection, transaction
from main.models import Arch, Repo
from .reporead import read_repo
@@ -53,6 +53,11 @@ class Command(BaseCommand):
self.path_template = path_template
notifier = self.setup_notifier()
+ # this thread is done using the database; all future access is done in
+ # the spawned read_repo() processes, so close the otherwise completely
+ # idle connection.
+ connection.close()
+
logger.info('Entering notifier loop')
notifier.loop()
@@ -61,14 +66,17 @@ class Command(BaseCommand):
if hasattr(thread, 'cancel'):
thread.cancel()
+ @transaction.commit_on_success
def setup_notifier(self):
'''Set up and configure the inotify machinery and logic.
This takes the provided or default path_template and builds a list of
directories we need to watch for database updates. It then validates
and passes these on to the various pyinotify pieces as necessary and
finally builds and returns a notifier object.'''
+ transaction.commit_manually()
arches = Arch.objects.filter(agnostic=False)
repos = Repo.objects.all()
+ transaction.set_dirty()
arch_path_map = {arch: None for arch in arches}
all_paths = set()
total_paths = 0
@@ -91,11 +99,6 @@ class Command(BaseCommand):
raise CommandError('path template did not uniquely '
'determine architecture for each file')
- # this thread is done using the database; all future access is done in
- # the spawned read_repo() processes, so close the otherwise completely
- # idle connection.
- connection.close()
-
# A proper atomic replacement of the database as done by rsync is type
# IN_MOVED_TO. repo-add/remove will finish with a IN_CLOSE_WRITE.
mask = pyinotify.IN_CLOSE_WRITE | pyinotify.IN_MOVED_TO