def METHOD_NAME(self):
    from django.utils import timezone
    from datetime import timedelta
    # environments locked for more than 30 seconds
    # they should be unlocked
    BuildEnvironment.objects.filter(
        Q(buildrequest__state__in=[BuildRequest.REQ_FAILED,
                                   BuildRequest.REQ_COMPLETED,
                                   BuildRequest.REQ_CANCELLING]) &
        Q(lock=BuildEnvironment.LOCK_LOCK) &
        Q(updated__lt=timezone.now() - timedelta(seconds=30))
    ).update(lock=BuildEnvironment.LOCK_FREE)
    # update all Builds that were in progress and failed to start
    for br in BuildRequest.objects.filter(
            state=BuildRequest.REQ_FAILED,
            build__outcome=Build.IN_PROGRESS):
        # transpose the launch errors in ToasterExceptions
        br.build.outcome = Build.FAILED
        for brerror in br.brerror_set.all():
            logger.debug("Saving error %s" % brerror)
            LogMessage.objects.create(build=br.build,
                                      level=LogMessage.EXCEPTION,
                                      message=brerror.errmsg)
        br.build.save()
        # we don't have a true build object here; hence, toasterui
        # didn't have a change to release the BE lock
        br.environment.lock = BuildEnvironment.LOCK_FREE
        br.environment.save()
    # update all BuildRequests without a build created
    for br in BuildRequest.objects.filter(build=None):
        br.build = Build.objects.create(project=br.project,
                                        completed_on=br.updated,
                                        started_on=br.created)
        br.build.outcome = Build.FAILED
        try:
            br.build.machine = br.brvariable_set.get(name='MACHINE').value
        except BRVariable.DoesNotExist:
            pass
        br.save()
        # transpose target information
        for brtarget in br.brtarget_set.all():
            Target.objects.create(build=br.build,
                                  target=brtarget.target,
                                  task=brtarget.task)
        # transpose the launch errors in ToasterExceptions
        for brerror in br.brerror_set.all():
            LogMessage.objects.create(build=br.build,
                                      level=LogMessage.EXCEPTION,
                                      message=brerror.errmsg)
        br.build.save()
    # Make sure the LOCK is removed for builds which have been fully
    # cancelled
    for br in BuildRequest.objects.filter(
                  Q(build__outcome=Build.CANCELLED) &
                  Q(state=BuildRequest.REQ_CANCELLING) &
                  ~Q(environment=None)):
        br.environment.lock = BuildEnvironment.LOCK_FREE
        br.environment.save()