mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 08:58:35 +00:00
Merge pull request #10053 from appwrite/fix-build-duration
Fix: build duration calculation
This commit is contained in:
commit
213cbf055a
2 changed files with 21 additions and 14 deletions
|
|
@ -209,6 +209,9 @@ class Builds extends Action
|
|||
Executor $executor,
|
||||
array $plan
|
||||
): void {
|
||||
$startTime = DateTime::now();
|
||||
$durationStart = \microtime(true);
|
||||
|
||||
$resourceKey = match ($resource->getCollection()) {
|
||||
'functions' => 'functionId',
|
||||
'sites' => 'siteId',
|
||||
|
|
@ -260,9 +263,6 @@ class Builds extends Action
|
|||
->setParam($resourceKey, $resource->getId())
|
||||
->setParam('deploymentId', $deployment->getId());
|
||||
|
||||
$startTime = DateTime::now();
|
||||
$durationStart = \microtime(true);
|
||||
|
||||
if ($deployment->getAttribute('status') === 'canceled') {
|
||||
Console::info('Build has been canceled');
|
||||
return;
|
||||
|
|
@ -810,9 +810,6 @@ class Builds extends Action
|
|||
throw $err;
|
||||
}
|
||||
|
||||
$endTime = DateTime::now();
|
||||
$durationEnd = \microtime(true);
|
||||
|
||||
$buildSizeLimit = (int)System::getEnv('_APP_COMPUTE_BUILD_SIZE_LIMIT', '2000000000');
|
||||
if (isset($plan['buildSize'])) {
|
||||
$buildSizeLimit = $plan['buildSize'] * 1000 * 1000;
|
||||
|
|
@ -821,10 +818,6 @@ class Builds extends Action
|
|||
throw new \Exception('Build size should be less than ' . number_format($buildSizeLimit / (1000 * 1000), 2) . ' MBs.');
|
||||
}
|
||||
|
||||
/** Update the build document */
|
||||
$deployment->setAttribute('buildStartedAt', DateTime::format((new \DateTime())->setTimestamp(floor($response['startTime']))));
|
||||
$deployment->setAttribute('buildEndedAt', $endTime);
|
||||
$deployment->setAttribute('buildDuration', \intval(\ceil($durationEnd - $durationStart)));
|
||||
$deployment->setAttribute('buildPath', $response['path']);
|
||||
$deployment->setAttribute('buildSize', $response['size']);
|
||||
$deployment->setAttribute('totalSize', $deployment->getAttribute('buildSize', 0) + $deployment->getAttribute('sourceSize', 0));
|
||||
|
|
@ -1191,6 +1184,15 @@ class Builds extends Action
|
|||
}
|
||||
}
|
||||
|
||||
$endTime = DateTime::now();
|
||||
$durationEnd = \microtime(true);
|
||||
$deployment->setAttribute('buildEndedAt', $endTime);
|
||||
$deployment->setAttribute('buildDuration', \intval(\ceil($durationEnd - $durationStart)));
|
||||
$deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);
|
||||
$queueForRealtime
|
||||
->setPayload($deployment->getArrayCopy())
|
||||
->trigger();
|
||||
|
||||
if ($dbForProject->getDocument('deployments', $deploymentId)->getAttribute('status') === 'canceled') {
|
||||
Console::info('Build has been canceled');
|
||||
return;
|
||||
|
|
@ -1234,7 +1236,7 @@ class Builds extends Action
|
|||
|
||||
// Combine with previous logs if deployment got past build process
|
||||
$previousLogs = '';
|
||||
if (!empty($deployment->getAttribute('buildEndedAt', ''))) {
|
||||
if (!is_null($deployment->getAttribute('buildSize', null))) {
|
||||
$previousLogs = $deployment->getAttribute('buildLogs', '');
|
||||
if (!empty($previousLogs)) {
|
||||
$message = $previousLogs . "\n" . $message;
|
||||
|
|
|
|||
|
|
@ -607,10 +607,8 @@ class RealtimeConsoleClientTest extends Scope
|
|||
$this->assertContains("projects.{$projectId}", $response['data']['channels']);
|
||||
$this->assertArrayHasKey('buildLogs', $response['data']['payload']);
|
||||
|
||||
if (!empty($response['data']['payload']['buildEndedAt'])) {
|
||||
$this->assertNotEmpty($response['data']['payload']['buildEndedAt']);
|
||||
if (!empty($response['data']['payload']['buildSize'])) {
|
||||
$this->assertNotEmpty($response['data']['payload']['buildStartedAt']);
|
||||
$this->assertNotEmpty($response['data']['payload']['buildDuration']);
|
||||
$this->assertNotEmpty($response['data']['payload']['buildPath']);
|
||||
$this->assertNotEmpty($response['data']['payload']['buildSize']);
|
||||
$this->assertNotEmpty($response['data']['payload']['totalSize']);
|
||||
|
|
@ -634,6 +632,13 @@ class RealtimeConsoleClientTest extends Scope
|
|||
$this->assertContains("projects.{$projectId}", $response['data']['channels']);
|
||||
$this->assertEquals("ready", $response['data']['payload']['status']);
|
||||
|
||||
$response = json_decode($client->receive(), true);
|
||||
$this->assertContains("functions.{$functionId}.deployments.{$deploymentId}.update", $response['data']['events']);
|
||||
$this->assertContains('console', $response['data']['channels']);
|
||||
$this->assertContains("projects.{$projectId}", $response['data']['channels']);
|
||||
$this->assertNotEmpty($response['data']['payload']['buildDuration']);
|
||||
$this->assertNotEmpty($response['data']['payload']['buildEndedAt']);
|
||||
|
||||
$client->close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue