"faults" management command: use atomic transaction PER HOST

This was an atomic transaction per ALL hosts (IIRC introduced in the hope of better speed).
But a frequently occurring problem was that it processed SOME hosts, then ran into a
database locked error and then it rolled back all the changes and aborted processing for all hosts.

This led to the strange behaviour that users got emails about abuse flag being set, but it wasn't set.
And also other stuff behaved wrong, like fault counters.

Now, the atomic transaction is per host, so a host is either processed completely and correctly or rolled back.
If an exception happens, the roll back occurs, the traceback is logged and we just continue with next host.
This commit is contained in:
Thomas Waldmann 2015-06-04 12:06:21 +02:00
parent 21c1a9dab7
commit 0f2e0235cb

View File

@ -2,6 +2,8 @@
dealing with the fault counters and available/abuse/abuse_blocked flags dealing with the fault counters and available/abuse/abuse_blocked flags
""" """
import traceback
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -118,8 +120,9 @@ class Command(BaseCommand):
reset_abuse_blocked = options['reset_abuse_blocked'] reset_abuse_blocked = options['reset_abuse_blocked']
flag_abuse = options['flag_abuse'] flag_abuse = options['flag_abuse']
notify_user = options['notify_user'] notify_user = options['notify_user']
with transaction.atomic():
for h in Host.objects.all(): for h in Host.objects.all():
try:
with transaction.atomic():
if show_client or show_server: if show_client or show_server:
output = u"" output = u""
if show_client: if show_client:
@ -160,3 +163,10 @@ class Command(BaseCommand):
if reset_abuse_blocked: if reset_abuse_blocked:
h.abuse_blocked = False h.abuse_blocked = False
h.save() h.save()
except Exception:
try:
msg = u"The following Exception occurred when processing host %s!\n" % (h.get_fqdn(), )
self.stderr.write(msg)
except Exception:
pass
traceback.print_exc()