Fix build execute - in some cases one build executed with many process

This commit is contained in:
Stepan Strelets 2017-04-04 23:12:20 +03:00
commit 80aa7d4c06
6 changed files with 114 additions and 26 deletions

View file

@ -310,4 +310,24 @@ class BuildStore extends Store
return false;
}
}
/**
* Update status only if it synced with db
* @param Build $build
* @param int $status
* @return bool
*/
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() and ($stmt->rowCount() == 1));
} catch (\Exception $e) {
return false;
}
}
}