Addressed PR Comments
This commit is contained in:
parent
fb0cd95b0a
commit
d5cc9d9eea
2 changed files with 8 additions and 8 deletions
|
@ -1025,10 +1025,10 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId')
|
|||
->param('security', false, new Boolean(true), 'Certificate verification, false for disabled or true for enabled.')
|
||||
->param('httpUser', '', new Text(256), 'Webhook HTTP user. Max length: 256 chars.', true)
|
||||
->param('httpPass', '', new Text(256), 'Webhook HTTP password. Max length: 256 chars.', true)
|
||||
->param('enable', false, new Boolean(), 'Enable a disabled webhook.', true)
|
||||
->param('enabled', false, new Boolean(), 'Enable a disabled webhook.', true)
|
||||
->inject('response')
|
||||
->inject('dbForConsole')
|
||||
->action(function (string $projectId, string $webhookId, string $name, array $events, string $url, bool $security, string $httpUser, string $httpPass, bool $enable, Response $response, Database $dbForConsole) {
|
||||
->action(function (string $projectId, string $webhookId, string $name, array $events, string $url, bool $security, string $httpUser, string $httpPass, bool $enabled, Response $response, Database $dbForConsole) {
|
||||
|
||||
$project = $dbForConsole->getDocument('projects', $projectId);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use Utopia\Queue\Message;
|
|||
class Webhooks extends Action
|
||||
{
|
||||
private array $errors = [];
|
||||
private const FAILEDATTEMPTSCOUNT = 10;
|
||||
private const MAX_FAILED_ATTEMPTS = 10;
|
||||
|
||||
public static function getName(): string
|
||||
{
|
||||
|
@ -123,19 +123,19 @@ class Webhooks extends Action
|
|||
if (false === \curl_exec($ch)) {
|
||||
$dbForConsole->increaseDocumentAttribute('webhooks', $webhook->getId(), 'attempts', 1);
|
||||
$webhook = $dbForConsole->getDocument('webhooks', $webhook->getId());
|
||||
$errorCount = $webhook->getAttribute('attempts');
|
||||
$lastErrorLogs = \curl_error($ch) . ' in events ' . implode(', ', $events);
|
||||
$webhook->setAttribute('logs', $lastErrorLogs);
|
||||
$attempts = $webhook->getAttribute('attempts');
|
||||
$logs = \curl_error($ch) . ' in events ' . implode(', ', $events);
|
||||
$webhook->setAttribute('logs', $logs);
|
||||
// $statusCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
||||
|
||||
if ($errorCount >= self::FAILEDATTEMPTSCOUNT) {
|
||||
if ($attempts >= self::MAX_FAILED_ATTEMPTS) {
|
||||
$webhook->setAttribute('enabled', false);
|
||||
}
|
||||
|
||||
$dbForConsole->updateDocument('webhooks', $webhook->getId(), $webhook);
|
||||
$dbForConsole->deleteCachedDocument('projects', $project->getId());
|
||||
|
||||
$this->errors[] = $lastErrorLogs;
|
||||
$this->errors[] = $logs;
|
||||
}
|
||||
|
||||
\curl_close($ch);
|
||||
|
|
Loading…
Reference in a new issue