forked from GithubBackups/healthchecks
sendreports now can be run concurrently too
This commit is contained in:
parent
b5a0ff3538
commit
252fa1f884
@ -30,6 +30,7 @@ class Command(BaseCommand):
|
||||
def handle_one_run(self):
|
||||
now = timezone.now()
|
||||
month_before = now - timedelta(days=30)
|
||||
month_after = now + timedelta(days=30)
|
||||
|
||||
report_due = Q(next_report_date__lt=now)
|
||||
report_not_scheduled = Q(next_report_date__isnull=True)
|
||||
@ -37,12 +38,25 @@ class Command(BaseCommand):
|
||||
q = Profile.objects.filter(report_due | report_not_scheduled)
|
||||
q = q.filter(reports_allowed=True)
|
||||
q = q.filter(user__date_joined__lt=month_before)
|
||||
profiles = list(q)
|
||||
|
||||
sent = 0
|
||||
for profile in q:
|
||||
if num_pinged_checks(profile) > 0:
|
||||
self.stdout.write(self.tmpl % profile.user.email)
|
||||
profile.send_report()
|
||||
sent += 1
|
||||
for profile in profiles:
|
||||
qq = Profile.objects
|
||||
qq = qq.filter(id=profile.id,
|
||||
next_report_date=profile.next_report_date)
|
||||
|
||||
num_updated = qq.update(next_report_date=month_after)
|
||||
if num_updated != 1:
|
||||
# Was updated elsewhere, skipping
|
||||
continue
|
||||
|
||||
if num_pinged_checks(profile) == 0:
|
||||
continue
|
||||
|
||||
self.stdout.write(self.tmpl % profile.user.email)
|
||||
profile.send_report()
|
||||
sent += 1
|
||||
|
||||
return sent
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user