Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/PHPCensor/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
// After execution we no longer want to record the information
// back to this specific build so the handler should be removed.
$this->logger->popHandler();
// destructor implicitly call flush
unset($buildDbLog);
} catch (\Exception $ex) {
$build->setStatus(Build::STATUS_FAILED);
$build->setFinished(new \DateTime());
Expand Down
33 changes: 31 additions & 2 deletions src/PHPCensor/Logging/BuildDBLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ class BuildDBLogHandler extends AbstractProcessingHandler

protected $logValue;

/**
* @var int last flush timestamp
*/
protected $flush_timestamp = 0;

/**
* @var int flush delay, seconds
*/
protected $flush_delay = 1;

/**
* @param Build $build
* @param bool $level
Expand All @@ -35,6 +45,24 @@ public function __construct(
$this->logValue = $build->getLog();
}

/**
* Destructor
*/
public function __destruct()
{
$this->flushData();
}

/**
* Flush buffered data
*/
protected function flushData()
{
$this->build->setLog($this->logValue);
Factory::getStore('Build')->save($this->build);
$this->flush_timestamp = time();
}

/**
* Write a log entry to the build log.
* @param array $record
Expand All @@ -45,8 +73,9 @@ protected function write(array $record)
$message = str_replace($this->build->currentBuildPath, '/', $message);

$this->logValue .= $message . PHP_EOL;
$this->build->setLog($this->logValue);

Factory::getStore('Build')->save($this->build);
if ($this->flush_timestamp < (time() - $this->flush_delay)) {
$this->flushData();
}
}
}
2 changes: 2 additions & 0 deletions src/PHPCensor/Worker/BuildWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public function startWorker()
// After execution we no longer want to record the information
// back to this specific build so the handler should be removed.
$this->logger->popHandler();
// destructor implicitly call flush
unset($buildDbLog);
} 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.
Expand Down