"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:
parent
21c1a9dab7
commit
0f2e0235cb
@ -2,6 +2,8 @@
|
||||
dealing with the fault counters and available/abuse/abuse_blocked flags
|
||||
"""
|
||||
|
||||
import traceback
|
||||
|
||||
from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
@ -118,8 +120,9 @@ class Command(BaseCommand):
|
||||
reset_abuse_blocked = options['reset_abuse_blocked']
|
||||
flag_abuse = options['flag_abuse']
|
||||
notify_user = options['notify_user']
|
||||
with transaction.atomic():
|
||||
for h in Host.objects.all():
|
||||
try:
|
||||
with transaction.atomic():
|
||||
if show_client or show_server:
|
||||
output = u""
|
||||
if show_client:
|
||||
@ -160,3 +163,10 @@ class Command(BaseCommand):
|
||||
if reset_abuse_blocked:
|
||||
h.abuse_blocked = False
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user