From 380a45f987f11365225b52d1e3bca12a62ab3582 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 10 Oct 2022 16:24:40 +0100 Subject: [PATCH 1/3] Add build time to deployment --- app/controllers/api/functions.php | 1 + src/Appwrite/Utopia/Response/Model/Deployment.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index d3a26b414e..f276cd2353 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -832,6 +832,7 @@ App::get('/v1/functions/:functionId/deployments') $result->setAttribute('status', $build->getAttribute('status', 'processing')); $result->setAttribute('buildStderr', $build->getAttribute('stderr', '')); $result->setAttribute('buildStdout', $build->getAttribute('stdout', '')); + $result->setAttribute('buildTime', $build->getAttribute('duration', 0)); } $response->dynamic(new Document([ diff --git a/src/Appwrite/Utopia/Response/Model/Deployment.php b/src/Appwrite/Utopia/Response/Model/Deployment.php index 7c93f566b4..8862d6a14e 100644 --- a/src/Appwrite/Utopia/Response/Model/Deployment.php +++ b/src/Appwrite/Utopia/Response/Model/Deployment.php @@ -82,6 +82,12 @@ class Deployment extends Model 'default' => '', 'example' => 'enabled', ]) + ->addRule('buildTime', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'The current build time in seconds.', + 'default' => 0, + 'example' => 128, + ]) ; } From fe4028f588c8e613eef18d7c55a977d5ee787d2d Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 19 Oct 2022 02:43:40 +0100 Subject: [PATCH 2/3] Add tests and add buildTime to worker --- app/workers/builds.php | 4 ++++ tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 2 ++ 2 files changed, 6 insertions(+) diff --git a/app/workers/builds.php b/app/workers/builds.php index bf780c6464..129d3f0bbf 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -181,6 +181,10 @@ class BuildsV1 extends Worker $build->setAttribute('stderr', $response['stderr']); $build->setAttribute('stdout', $response['response']); + /* Also update the deployment buildTime */ + $deployment->setAttribute('buildTime', $response['duration']); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); + Console::success("Build id: $buildId created"); /** Set auto deploy */ diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 5e498368ea..7694bf8ac2 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -550,6 +550,7 @@ class FunctionsCustomServerTest extends Scope $this->assertIsArray($function['body']['deployments']); $this->assertCount(2, $function['body']['deployments']); $this->assertEquals($function['body']['deployments'][0]['$id'], $data['deploymentId']); + $this->assertGreaterThanOrEqual(2, $function['body']['deployments'][0]['buildTime']); return $data; } @@ -568,6 +569,7 @@ class FunctionsCustomServerTest extends Scope ], $this->getHeaders())); $this->assertEquals(200, $function['headers']['status-code']); + $this->assertEquals(0, $function['body']['buildTime']); /** * Test for FAILURE From 60e924b62b9a5f6a4197fa7c8fd8c7848dd24d89 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 19 Oct 2022 02:50:48 +0100 Subject: [PATCH 3/3] Run Linter --- app/workers/builds.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/workers/builds.php b/app/workers/builds.php index 129d3f0bbf..f31db88ab3 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -182,7 +182,7 @@ class BuildsV1 extends Worker $build->setAttribute('stdout', $response['response']); /* Also update the deployment buildTime */ - $deployment->setAttribute('buildTime', $response['duration']); + $deployment->setAttribute('buildTime', $response['duration']); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); Console::success("Build id: $buildId created");