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):
|
def handle_one_run(self):
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
month_before = now - timedelta(days=30)
|
month_before = now - timedelta(days=30)
|
||||||
|
month_after = now + timedelta(days=30)
|
||||||
|
|
||||||
report_due = Q(next_report_date__lt=now)
|
report_due = Q(next_report_date__lt=now)
|
||||||
report_not_scheduled = Q(next_report_date__isnull=True)
|
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 = Profile.objects.filter(report_due | report_not_scheduled)
|
||||||
q = q.filter(reports_allowed=True)
|
q = q.filter(reports_allowed=True)
|
||||||
q = q.filter(user__date_joined__lt=month_before)
|
q = q.filter(user__date_joined__lt=month_before)
|
||||||
|
profiles = list(q)
|
||||||
|
|
||||||
sent = 0
|
sent = 0
|
||||||
for profile in q:
|
for profile in profiles:
|
||||||
if num_pinged_checks(profile) > 0:
|
qq = Profile.objects
|
||||||
self.stdout.write(self.tmpl % profile.user.email)
|
qq = qq.filter(id=profile.id,
|
||||||
profile.send_report()
|
next_report_date=profile.next_report_date)
|
||||||
sent += 1
|
|
||||||
|
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
|
return sent
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user