feat: implement webhook tasker with async/sync fallback (#27378)
* feat: implement webhook tasker with async/sync fallback This PR implements a webhook tasker with async/sync fallback architecture to fix failing E2E tests. The solution follows the existing proration tasker pattern and uses Dependency Injection with @evyweb/ioctopus. Key changes: - Create IWebhookTasker interface for webhook delivery - Implement WebhookSyncTasker for immediate execution (E2E tests) - Implement WebhookAsyncTasker for queued execution (production) - Create main WebhookTasker class extending Tasker<IWebhookTasker> - Add DI modules and tokens for all tasker components - Update WebhookTaskerProducerService to use new WebhookTasker - Add unit tests for sync and async taskers The ENABLE_ASYNC_TASKER flag automatically selects the appropriate mode: - Production: Uses WebhookAsyncTasker to queue tasks - E2E Tests: Uses WebhookSyncTasker for immediate execution This ensures webhooks are delivered immediately in E2E tests without requiring the cron job that processes queued tasks. Co-Authored-By: [email protected] <[email protected]> * fix: update WebhookTaskerProducerService tests for new interface Update tests to use the new deps-based constructor and mockWebhookTasker.deliverWebhook instead of mockTasker.create Co-Authored-By: [email protected] <[email protected]> * fix: use moduleLoader pattern for WebhookProducerService in container Co-Authored-By: [email protected] <[email protected]> * refactor: replace InternalTasker with Trigger.dev for webhook delivery This commit refactors the WebhookTasker to use Trigger.dev instead of InternalTasker, following the pattern established in BookingEmailAndSmsTasker and PlatformOrganizationBillingTasker (PR #26803). Changes: - Replace WebhookAsyncTasker with WebhookTriggerTasker that uses trigger.dev - Create trigger.dev task files (deliver-webhook.ts, config.ts, schema.ts) - Update DI modules to use WebhookTriggerTasker - Remove old InternalTasker-based implementation - Update unit tests for new implementation The WebhookSyncTasker continues to execute webhooks immediately for E2E tests where ENABLE_ASYNC_TASKER is automatically false. Co-Authored-By: [email protected] <[email protected]> * fix: update comments to reflect Trigger.dev usage instead of InternalTasker Co-Authored-By: unknown <> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
18 files changed
+538
-67
No files matched your search
@@ -1,18 +1,38 @@
|
||||
import { createModule } from "@evyweb/ioctopus";
|
||||
|
||||
import { bindModuleToClassOnToken, createModule, type ModuleLoader } from "@calcom/features/di/di";
|
||||
import { moduleLoader as loggerServiceModule } from "@calcom/features/di/shared/services/logger.service";
|
||||
import { WebhookTaskerProducerService } from "@calcom/features/webhooks/lib/service/WebhookTaskerProducerService";
|
||||
|
||||
import { SHARED_TOKENS } from "../../shared/shared.tokens";
|
||||
import { moduleLoader as webhookTaskerModule } from "../tasker/WebhookTasker.module";
|
||||
import { WEBHOOK_TOKENS } from "../Webhooks.tokens";
|
||||
|
||||
/**
|
||||
* Producer Service Module
|
||||
*
|
||||
*
|
||||
* Binds the lightweight WebhookTaskerProducerService.
|
||||
* Dependencies: Only Tasker and Logger (no heavy deps).
|
||||
* Dependencies: WebhookTasker and Logger.
|
||||
*
|
||||
* The WebhookTasker automatically handles async/sync mode selection:
|
||||
* - Production: Queues to Trigger.dev for background processing
|
||||
* - E2E Tests: Executes immediately via WebhookSyncTasker
|
||||
*/
|
||||
export const webhookProducerServiceModule = createModule();
|
||||
const thisModule = createModule();
|
||||
const token = WEBHOOK_TOKENS.WEBHOOK_PRODUCER_SERVICE;
|
||||
const moduleToken = WEBHOOK_TOKENS.WEBHOOK_PRODUCER_SERVICE_MODULE;
|
||||
|
||||
webhookProducerServiceModule
|
||||
.bind(WEBHOOK_TOKENS.WEBHOOK_PRODUCER_SERVICE)
|
||||
.toClass(WebhookTaskerProducerService, [SHARED_TOKENS.TASKER, SHARED_TOKENS.LOGGER]);
|
||||
const loadModule = bindModuleToClassOnToken({
|
||||
module: thisModule,
|
||||
moduleToken,
|
||||
token,
|
||||
classs: WebhookTaskerProducerService,
|
||||
depsMap: {
|
||||
webhookTasker: webhookTaskerModule,
|
||||
logger: loggerServiceModule,
|
||||
},
|
||||
});
|
||||
|
||||
export const moduleLoader = {
|
||||
token,
|
||||
loadModule,
|
||||
} satisfies ModuleLoader;
|
||||
|
||||
export const webhookProducerServiceModule = thisModule;
|
||||
Reference in new issue
Block a user