Skip to content

Commit

Permalink
Add buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed Jan 12, 2024
1 parent 61637c5 commit 302103e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/cli/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ export const MIN_PASSWORD_CHAR_LENGTH = 8;
export const MAX_PASSWORD_CHAR_LENGTH = 64;

export const TEST_WEBHOOK_TIMEOUT = 2 * TIME.MINUTE;

export const TEST_WEBHOOK_TIMEOUT_BUFFER = 30 * TIME.SECOND;
10 changes: 7 additions & 3 deletions packages/cli/src/services/test-webhook-registrations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Service } from 'typedi';
import { CacheService } from '@/services/cache/cache.service';
import { type IWebhookData } from 'n8n-workflow';
import type { IWorkflowDb } from '@/Interfaces';
import { TEST_WEBHOOK_TIMEOUT } from '@/constants';
import { TEST_WEBHOOK_TIMEOUT, TEST_WEBHOOK_TIMEOUT_BUFFER } from '@/constants';

export type TestWebhookRegistration = {
sessionId?: string;
Expand All @@ -27,9 +27,13 @@ export class TestWebhookRegistrationsService {
* handles a webhook might not be the same as the main process that created
* the webhook. If so, after the test webhook has been successfully executed,
* the handler process commands the creator process to clear its test webhooks.
* We set a TTL on the key so that it is cleared even on creator process crash.
* We set a TTL on the key so that it is cleared even on creator process crash,
* with an additional buffer to ensure this safeguard expiration will not delete
* the key before the regular test webhook timeout fetches the key to delete it.
*/
await this.cacheService.expire(this.cacheKey, TEST_WEBHOOK_TIMEOUT);
const ttl = TEST_WEBHOOK_TIMEOUT + TEST_WEBHOOK_TIMEOUT_BUFFER;

await this.cacheService.expire(this.cacheKey, ttl);
}

async deregister(arg: IWebhookData | string) {
Expand Down

0 comments on commit 302103e

Please sign in to comment.