Skip to content

Commit 377e00c

Browse files
committed
retry on case of specific snowflake error
1 parent adcd5bf commit 377e00c

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

src/Connection/Snowflake/SnowflakeStatement.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
use Doctrine\DBAL\Driver\Statement;
88
use Doctrine\DBAL\ParameterType;
99
use Keboola\TableBackendUtils\Connection\Exception\DriverException;
10+
use Retry\BackOff\ExponentialBackOffPolicy;
11+
use Retry\BackOff\ExponentialRandomBackOffPolicy;
12+
use Retry\BackOff\UniformRandomBackOffPolicy;
13+
use Retry\Policy\CallableRetryPolicy;
14+
use Retry\Policy\SimpleRetryPolicy;
15+
use Retry\RetryProxy;
1016
use Throwable;
1117

1218
class SnowflakeStatement implements Statement
@@ -81,9 +87,33 @@ public function execute($params = null): Result
8187
}
8288
}
8389

90+
$proxy = new RetryProxy(
91+
new CallableRetryPolicy(
92+
function (Throwable $e): bool {
93+
if (str_contains($e->getMessage(), 'SYSTEM$ALLOWLIST')) {
94+
// Retry in case of SYSTEM$ALLOWLIST error #prod_24_7___inc_25140
95+
// this is usually accompanied with SNFLK incidents
96+
// or can happen in case hostname is wrong
97+
return true;
98+
}
99+
return false;
100+
},
101+
5, // 5 attempts
102+
),
103+
new UniformRandomBackOffPolicy(
104+
3_000, // 3 seconds
105+
10_000, // 10 seconds
106+
),
107+
);
108+
84109
try {
85-
odbc_execute($this->stmt, $this->repairBinding($this->params));
86-
} catch (Throwable $e) {
110+
$proxy->call(function () {
111+
odbc_execute(
112+
$this->stmt,
113+
$this->repairBinding($this->params),
114+
);
115+
});
116+
} catch (Throwable) {
87117
throw DriverException::newFromHandle($this->dbh);
88118
}
89119

0 commit comments

Comments
 (0)