From 079f7480e1e8d19f43958c2cd7b5f87660ab1b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Jodas?= Date: Tue, 26 Aug 2025 22:31:18 +0200 Subject: [PATCH 1/3] Add exponential backoff for job status polling --- src/Client.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 05d4ad9..047d9a9 100644 --- a/src/Client.php +++ b/src/Client.php @@ -360,6 +360,7 @@ public function waitForJobCompletion(string $queryJobId, int $maxWaitSeconds = 3 { $startTime = time(); + $tries = 0; while (time() - $startTime < $maxWaitSeconds) { $status = $this->getJobStatus($queryJobId); @@ -367,7 +368,10 @@ public function waitForJobCompletion(string $queryJobId, int $maxWaitSeconds = 3 return $status; } - sleep(1); + // 10, 20, 40, 80, 160, 320, 640, 1000ms (max) + $waitMilliseconds = min(pow(2, $tries)*10, 1000); + usleep($waitMilliseconds * 1000); + $tries++; } throw new ClientException( From 498b91e7f008ad1a61c9dfa56c33757f6193c12e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Jodas?= Date: Tue, 26 Aug 2025 22:31:27 +0200 Subject: [PATCH 2/3] fix cancel test --- tests/Functional/QueryServiceFunctionalTest.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/tests/Functional/QueryServiceFunctionalTest.php b/tests/Functional/QueryServiceFunctionalTest.php index 6f19594..9d704a5 100644 --- a/tests/Functional/QueryServiceFunctionalTest.php +++ b/tests/Functional/QueryServiceFunctionalTest.php @@ -127,22 +127,12 @@ public function testSubmitTransactionalQuery(): void public function testCancelQueryJob(): void { - // Create test table - $tableName = $this->createTestTable(); - - // Submit a cross join query that takes some time to process $response = $this->queryClient->submitQueryJob( $this->getTestBranchId(), $this->getTestWorkspaceId(), [ 'statements' => [ - sprintf(' - SELECT a.id, b.id as id2, a.name, b.name as name2 - FROM %s a - CROSS JOIN %s b - CROSS JOIN %s c - ORDER BY 1, 2 - ', $tableName, $tableName, $tableName), + 'CALL SYSTEM$WAIT(10);', // Wait for 10 seconds to allow time for cancellation ], 'transactional' => false, ], From bff26b568599dec5334bba5cbf82ee36bf4eb995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Jodas?= Date: Tue, 26 Aug 2025 23:02:43 +0200 Subject: [PATCH 3/3] update waitMilliseconds backoff --- src/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 047d9a9..6fa98f0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -368,8 +368,8 @@ public function waitForJobCompletion(string $queryJobId, int $maxWaitSeconds = 3 return $status; } - // 10, 20, 40, 80, 160, 320, 640, 1000ms (max) - $waitMilliseconds = min(pow(2, $tries)*10, 1000); + // 60, 70, 90, 130, 210, 370, 690, 1000ms (max) + $waitMilliseconds = min(50+pow(2, $tries)*10, 1000); usleep($waitMilliseconds * 1000); $tries++; }