Permalink
Browse files

Improved worker.

  • Loading branch information...
corpsee committed Oct 6, 2018
1 parent d6d11ad commit cb170395a5b313172939eefdd85bb971a9508f4a
View
@@ -47,7 +47,7 @@
"require": {
"php": ">=5.6.0",
"ext-openssl": "*",
"ext-pdo": "*",
"ext-PDO": "*",
"ext-json": "*",
"ext-xml": "*",
"ext-curl": "*",
View
@@ -119,6 +119,14 @@ public function __construct(Build $build, LoggerInterface $logger = null)
$this->buildErrorWriter = new BuildErrorWriter($this->build->getProjectId(), $this->build->getId());
}
/**
* @return BuildLogger
*/
public function getBuildLogger()
{
return $this->buildLogger;
}
/**
* @return null|string
*/
@@ -180,24 +188,13 @@ public function getBuildProjectTitle()
return $this->build->getProject()->getTitle();
}
/**
* Run the active build.
*/
public function execute()
{
// check current status
if ($this->build->getStatus() != Build::STATUS_PENDING) {
throw new BuilderException('Can`t build - status is not pending', BuilderException::FAIL_START);
}
// set status only if current status pending
if (!$this->build->setStatusSync(Build::STATUS_RUNNING)) {
throw new BuilderException('Can`t build - unable change status to running', BuilderException::FAIL_START);
}
// Update the build in the database, ping any external services.
$this->build->setStatus(Build::STATUS_RUNNING);
$this->build->setStartDate(new \DateTime());
$this->store->save($this->build);
$this->build->sendStatusPostback();
$success = true;
$previousBuild = $this->build->getProject()->getPreviousBuild($this->build->getBranch());
View

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,7 @@
<?php
namespace PHPCensor\Exception;
class Exception extends \Exception
{
}
@@ -2,7 +2,7 @@
namespace PHPCensor\Exception;
class HttpException extends \Exception
class HttpException extends Exception
{
/**
* @var integer
@@ -2,6 +2,6 @@
namespace PHPCensor\Exception;
class InvalidArgumentException extends \InvalidArgumentException
class InvalidArgumentException extends Exception
{
}
@@ -88,7 +88,7 @@ public function logSuccess($message)
public function logFailure($message, \Exception $exception = null)
{
$context = [];
// The psr3 log interface stipulates that exceptions should be passed
// as the exception key in the context array.
if ($exception) {
View
@@ -23,6 +23,8 @@ class Model
/**
* @param array $initialData
*
* @throws InvalidArgumentException
*/
public function __construct($initialData = [])
{
View
@@ -90,28 +90,6 @@ public function addExtraValue($name, $value)
$this->setExtra($extra);
}
/**
* Set the value of status only if it synced with db. Must not be null.
*
* @param integer $value
*
* @return boolean
*/
public function setStatusSync($value)
{
$this->validateNotNull('status', $value);
$this->validateInt('status', $value);
if ($this->data['status'] !== $value) {
$store = Factory::getStore('Build');
if ($store->updateStatusSync($this, $value)) {
$this->data['status'] = $value;
return true;
}
}
return false;
}
/**
* Get BuildError models by BuildId for this Build.
*
View
@@ -478,29 +478,6 @@ public function setMeta($buildId, $key, $value)
$store->save($meta);
}
/**
* Update status only if it synced with db
*
* @param Build $build
* @param integer $status
*
* @return boolean
*/
public function updateStatusSync($build, $status)
{
try {
$query = 'UPDATE {{build}} SET status = :status_new WHERE {{id}} = :id AND {{status}} = :status_current';
$stmt = Database::getConnection('write')->prepareCommon($query);
$stmt->bindValue(':id', $build->getId(), \PDO::PARAM_INT);
$stmt->bindValue(':status_current', $build->getStatus(), \PDO::PARAM_INT);
$stmt->bindValue(':status_new', $status, \PDO::PARAM_INT);
return ($stmt->execute() && ($stmt->rowCount() == 1));
} catch (\Exception $e) {
return false;
}
}
public function deleteAllByProject($projectId)
{
$q = Database::getConnection('write')
Oops, something went wrong.

0 comments on commit cb17039

Please sign in to comment.