Browse Source

sendreports now can be run concurrently too

pull/84/head
Pēteris Caune 8 years ago
parent
commit
252fa1f884
1 changed files with 19 additions and 5 deletions
  1. +19
    -5
      hc/api/management/commands/sendreports.py

+ 19
- 5
hc/api/management/commands/sendreports.py View File

@ -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…
Cancel
Save