From 514d14fc977fd0cb003938f90de8da06909a5162 Mon Sep 17 00:00:00 2001 From: steebchen Date: Wed, 12 Jun 2024 23:59:37 +0100 Subject: [PATCH] automatically register workflows --- examples/webhooks.e2e.ts | 1 - src/clients/rest/generated/data-contracts.ts | 4 ++-- src/clients/worker/worker.ts | 5 ++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/webhooks.e2e.ts b/examples/webhooks.e2e.ts index 9433ad5..9590672 100644 --- a/examples/webhooks.e2e.ts +++ b/examples/webhooks.e2e.ts @@ -56,7 +56,6 @@ describe('webhooks', () => { await worker.registerWebhook({ secret, url: `http://localhost:${port}/webhook`, - workflows: ['simple-webhook-workflow'], }); console.log('starting worker...'); diff --git a/src/clients/rest/generated/data-contracts.ts b/src/clients/rest/generated/data-contracts.ts index 540780f..8681abd 100644 --- a/src/clients/rest/generated/data-contracts.ts +++ b/src/clients/rest/generated/data-contracts.ts @@ -1026,8 +1026,8 @@ export interface WebhookWorker { export interface WebhookWorkerCreateRequest { /** The webhook url. */ url: string; - /** The workflow IDs or names to register for this webhook worker. */ - workflows: string[]; + /** The workflow IDs or names to register for this webhook worker. If not provided, workflows will be automatically detected. */ + workflows?: string[]; /** * The secret key for validation. If not provided, a random secret will be generated. * @minLength 32 diff --git a/src/clients/worker/worker.ts b/src/clients/worker/worker.ts index a0ef943..b5c15e3 100644 --- a/src/clients/worker/worker.ts +++ b/src/clients/worker/worker.ts @@ -39,6 +39,7 @@ export class Worker { logger: Logger; registeredWorkflowPromises: Array> = []; + registeredWorkflowIds: string[] = []; constructor( client: HatchetClient, @@ -98,7 +99,7 @@ export class Worker { } async registerWebhook(webhook: WebhookWorkerCreateRequest) { - return this.client.admin.webhook_create(webhook); + return this.client.admin.webhook_create({ ...webhook, workflows: this.registeredWorkflowIds }); } // @deprecated @@ -140,6 +141,8 @@ export class Worker { } : undefined; + this.registeredWorkflowIds.push(workflow.id); + const registeredWorkflow = this.client.admin.put_workflow({ name: workflow.id, description: workflow.description,