1
0
Fork 0
mirror of synced 2024-09-29 17:01:37 +13:00

Addressed PR Comments

This commit is contained in:
Khushboo Verma 2023-12-15 01:45:17 +05:30
parent fb0cd95b0a
commit d5cc9d9eea
2 changed files with 8 additions and 8 deletions

View file

@ -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);

View file

@ -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);