diff --git a/src/PHPCensor/Command/RunCommand.php b/src/PHPCensor/Command/RunCommand.php index 7fb53f30..1ae13d51 100644 --- a/src/PHPCensor/Command/RunCommand.php +++ b/src/PHPCensor/Command/RunCommand.php @@ -13,7 +13,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use b8\Store\Factory; use PHPCensor\Builder; -use PHPCensor\BuilderException; use PHPCensor\BuildFactory; use PHPCensor\Model\Build; @@ -83,9 +82,9 @@ class RunCommand extends Command $this->logger->pushProcessor(new LoggedBuildContextTidier()); $this->logger->addInfo('Finding builds to process'); - /** @var BuildStore $store */ - $store = Factory::getStore('Build'); - $result = $store->getByStatus(Build::STATUS_PENDING, $this->maxBuilds); + /** @var BuildStore $buildStore */ + $buildStore = Factory::getStore('Build'); + $result = $buildStore->getByStatus(Build::STATUS_PENDING, $this->maxBuilds); $this->logger->addInfo(sprintf('Found %d builds', count($result['items']))); @@ -111,26 +110,14 @@ class RunCommand extends Command try { $builder = new Builder($build, $this->logger); $builder->execute(); - - } catch (BuilderException $ex) { - $this->logger->addError($ex->getMessage()); - switch($ex->getCode()) { - case BuilderException::FAIL_START: - // non fatal - break; - default: - $build->setStatus(Build::STATUS_FAILED); - $build->setFinished(new \DateTime()); - $build->setLog($build->getLog() . PHP_EOL . PHP_EOL . $ex->getMessage()); - $store->save($build); - break; - } - } catch (\Exception $ex) { + $this->logger->addError($ex->getMessage()); + $build->setStatus(Build::STATUS_FAILED); $build->setFinished(new \DateTime()); $build->setLog($build->getLog() . PHP_EOL . PHP_EOL . $ex->getMessage()); - $store->save($build); + $buildStore->save($build); + $build->sendStatusPostback(); } // After execution we no longer want to record the information diff --git a/src/PHPCensor/Worker/BuildWorker.php b/src/PHPCensor/Worker/BuildWorker.php index 86e55038..65046caa 100644 --- a/src/PHPCensor/Worker/BuildWorker.php +++ b/src/PHPCensor/Worker/BuildWorker.php @@ -7,7 +7,6 @@ use Monolog\Logger; use Pheanstalk\Job; use Pheanstalk\Pheanstalk; use PHPCensor\Builder; -use PHPCensor\BuilderException; use PHPCensor\BuildFactory; use PHPCensor\Logging\BuildDBLogHandler; use PHPCensor\Model\Build; @@ -109,23 +108,6 @@ class BuildWorker try { $builder = new Builder($build, $this->logger); $builder->execute(); - - } catch (BuilderException $ex) { - $this->logger->addError($ex->getMessage()); - switch($ex->getCode()) { - case BuilderException::FAIL_START: - // non fatal - $this->pheanstalk->release($job); - unset($job); - break; - default: - $build->setStatus(Build::STATUS_FAILED); - $build->setFinished(new \DateTime()); - $build->setLog($build->getLog() . PHP_EOL . PHP_EOL . $ex->getMessage()); - $buildStore->save($build); - $build->sendStatusPostback(); - break; - } } catch (\PDOException $ex) { // If we've caught a PDO Exception, it is probably not the fault of the build, but of a failed // connection or similar. Release the job and kill the worker. @@ -133,6 +115,8 @@ class BuildWorker $this->pheanstalk->release($job); unset($job); } catch (\Exception $ex) { + $this->logger->addError($ex->getMessage()); + $build->setStatus(Build::STATUS_FAILED); $build->setFinished(new \DateTime()); $build->setLog($build->getLog() . PHP_EOL . PHP_EOL . $ex->getMessage());