Fix referenced before assignment for BuildCompletedEvent

It was possible for duration to be referenced before assignment.

  Traceback (most recent call last):
    File "/usr/local/lib/python2.7/dist-packages/zuul/scheduler.py", line 1108, in _doBuildCompletedEvent
      except Exception:
  UnboundLocalError: local variable 'duration' referenced before assignment

Change-Id: I48446f9cdb23bfd37c1a843dbcf90f94492a0678
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
diff --git a/zuul/scheduler.py b/zuul/scheduler.py
index beab879..c3fd3c9 100644
--- a/zuul/scheduler.py
+++ b/zuul/scheduler.py
@@ -1103,10 +1103,11 @@
             return
         if build.end_time and build.start_time and build.result:
             duration = build.end_time - build.start_time
-        try:
-            self.time_database.update(build.job.name, duration, build.result)
-        except Exception:
-            self.log.exception("Exception recording build time:")
+            try:
+                self.time_database.update(
+                    build.job.name, duration, build.result)
+            except Exception:
+                self.log.exception("Exception recording build time:")
         pipeline.manager.onBuildCompleted(event.build)
 
     def _doMergeCompletedEvent(self, event):