You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
756 B

  1. from django.core.management.base import BaseCommand
  2. from hc.api.models import Channel, Notification
  3. class Command(BaseCommand):
  4. help = "Backfill Channel.last_notify and Channel.last_error"
  5. def handle(self, *args, **options):
  6. total = 0
  7. for channel in Channel.objects.all():
  8. q = Channel.objects.filter(id=channel.id)
  9. try:
  10. n = Notification.objects.filter(channel=channel).latest()
  11. q.update(last_notify=n.created, last_error=n.error)
  12. total += 1
  13. except Notification.DoesNotExist:
  14. if channel.last_error:
  15. q.update(last_error="")
  16. total += 1
  17. return "Done! Updated %d channels." % total