From b9cce5d12baa40deb21ab4f36be19e3a41e18ad4 Mon Sep 17 00:00:00 2001 From: 玄猫 Date: Sun, 19 Jan 2025 20:34:42 +0800 Subject: feat(webhook): Implement webhook functionality for bookmark events (#852) * feat(webhook): Implement webhook functionality for bookmark events - Added WebhookWorker to handle webhook requests. - Integrated webhook triggering in crawlerWorker after video processing. - Updated main worker initialization to include WebhookWorker. - Enhanced configuration to support webhook URLs, token, and timeout. - Documented webhook configuration options in the documentation. - Introduced zWebhookRequestSchema for validating webhook requests. * feat(webhook): Update webhook handling and configuration - Changed webhook operation type from "create" to "crawled" in crawlerWorker and documentation. - Enhanced webhook retry logic in WebhookWorker to support multiple attempts. - Updated Docker configuration to include new webhook environment variables. - Improved validation for webhook configuration in shared config. - Adjusted zWebhookRequestSchema to reflect the new operation type. - Updated documentation to clarify webhook configuration options and usage. * minor modifications --------- Co-authored-by: Mohamed Bassem --- packages/shared/queues.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'packages/shared/queues.ts') diff --git a/packages/shared/queues.ts b/packages/shared/queues.ts index 7afb8774..b0002a29 100644 --- a/packages/shared/queues.ts +++ b/packages/shared/queues.ts @@ -158,3 +158,30 @@ export const AssetPreprocessingQueue = keepFailedJobs: false, }, ); + +//Webhook worker +export const zWebhookRequestSchema = z.object({ + bookmarkId: z.string(), + operation: z.enum(["crawled"]), +}); +export type ZWebhookRequest = z.infer; +export const WebhookQueue = new SqliteQueue( + "webhook_queue", + queueDB, + { + defaultJobArgs: { + numRetries: 3, + }, + keepFailedJobs: false, + }, +); + +export async function triggerWebhookWorker( + bookmarkId: string, + operation: "crawled", +) { + await WebhookQueue.enqueue({ + bookmarkId, + operation, + }); +} -- cgit v1.2.3-70-g09d2