/**
  * @param \App\Model\User $user
  *
  * @return \App\Model\Build[]
  */
 private function getRunningBuilds(User $user)
 {
     $builds = $this->repository->findRunningBuildsByUser($user);
     // demo builds don't count in the running builds quota
     $builds = array_filter($builds, function (Build $build) {
         return !$build->isDemo();
     });
     return $builds;
 }
 public function onBuildFinished(BuildFinishedEvent $event)
 {
     $build = $event->getBuild();
     if (!$build->isRunning()) {
         return;
     }
     $previousBuild = $this->repository->findPreviousBuild($build);
     if (!$previousBuild) {
         return;
     }
     $this->logger->info('detected previous build', ['previous_build_id' => $previousBuild->getId()]);
     $this->scheduler->stop($previousBuild, Build::STATUS_OBSOLETE);
 }