Skip to content

Commit

Permalink
automatically register workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen committed Jun 12, 2024
1 parent 322df0c commit 19ff89e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 0 additions & 1 deletion examples/webhooks.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ describe('webhooks', () => {
await worker.registerWebhook({
secret,
url: `http://localhost:${port}/webhook`,
workflows: ['simple-webhook-workflow'],
});

console.log('starting worker...');
Expand Down
4 changes: 2 additions & 2 deletions src/clients/rest/generated/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/clients/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class Worker {
logger: Logger;

registeredWorkflowPromises: Array<Promise<any>> = [];
registeredWorkflowIds: string[] = [];

constructor(
client: HatchetClient,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 19ff89e

Please sign in to comment.