from django.contrib.auth.models import AnonymousUser
from django.core.management.base import BaseCommand

from metaci.build.models import Build
from metaci.build.models import Rebuild


class Command(BaseCommand):
    # NOTE: This should only be run at heroku postdeploy stage
    help = 'Rebuild all builds/rebuilds with status "running"'

    def handle(self, *args, **options):
        for rebuild in Rebuild.objects.filter(status='running'):
            rebuild.status = 'error'
            rebuild.error_message = 'Interrupted by dyno restart while running'
            rebuild.save()
        for build in Build.objects.filter(status='running'):
            build.status = 'error'
            build.error_message = 'Interrupted by dyno restart while running'
            build.save()

@@ -517,35 +517,22 @@
  = '
-Interrupted by dyno
+System
  restart
  whi
@@ -519,39 +519,51 @@
  'System restart
+ed
  while 
+build was 
 running'%0A       
@@ -717,35 +717,22 @@
  = '
-Interrupted by dyno
+System
  restart
  whi
@@ -727,23 +727,35 @@
  restart
+ed
  while 
+build was 
 running'

update error message in handle_orphaned_builds