Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen committed Jun 10, 2024
1 parent 49ac3fb commit b633f4d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
7 changes: 5 additions & 2 deletions examples/webhooks.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Hatchet from '../src/sdk';

const port = 8369;

describe('e2e', () => {
describe('webhooks', () => {
let hatchet: Hatchet;
let worker: Worker;

Expand All @@ -19,7 +19,7 @@ describe('e2e', () => {
await sleep(2000);
});

it('should pass a simple workflow', async () => {
it('should pass a webhook workflow', async () => {
let invoked = 0;

const workflow: Workflow = {
Expand Down Expand Up @@ -58,6 +58,9 @@ describe('e2e', () => {
workflows: ['simple-webhook-workflow'],
});

// wait for engine to pick up the webhook worker
await sleep(30000 + 3000);

const handler = hatchet.webhooks(workflow);

const server = createServer(handler.httpHandler({ secret }));
Expand Down
9 changes: 7 additions & 2 deletions src/clients/dispatcher/action-listener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { DispatcherClient as PbDispatcherClient, AssignedAction } from '@hatchet/protoc/dispatcher';
import {
DispatcherClient as PbDispatcherClient,
AssignedAction,
actionTypeToJSON,
} from '@hatchet/protoc/dispatcher';

import { Status } from 'nice-grpc';
import { ClientConfig } from '@clients/hatchet-client/client-config';
Expand Down Expand Up @@ -27,7 +31,7 @@ export const ActionObject = z.object({
stepId: z.string(),
stepRunId: z.string(),
actionId: z.string(),
actionType: z.number().optional(),
actionType: z.string().optional(),
actionPayload: z.string(),
workflowRunId: z.string(),
getGroupKeyRunId: z.string().optional(),
Expand Down Expand Up @@ -77,6 +81,7 @@ export class ActionListener {
for await (const assignedAction of listenClient) {
const action: Action = {
...assignedAction,
actionType: actionTypeToJSON(assignedAction.actionType),
};

yield action;
Expand Down
2 changes: 1 addition & 1 deletion src/clients/worker/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class WebhookHandler {
const handle = async () => {
const body = await this.getBody(req);

await this.handle(body, secret, req.headers['x-hatchet-signature'] as any);
this.handle(body, secret, req.headers['x-hatchet-signature'] as any);

res.writeHead(200, 'OK');
res.end();
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 @@ -7,6 +7,7 @@ import {
ActionType,
GroupKeyActionEvent,
GroupKeyActionEventType,
actionTypeFromJSON,
} from '@hatchet/protoc/dispatcher';
import HatchetPromise from '@util/hatchet-promise/hatchet-promise';
import { Workflow } from '@hatchet/workflow';
Expand Down Expand Up @@ -468,7 +469,9 @@ export class Worker {
}

handleAction(action: Action) {
const type = action.actionType || ActionType.START_STEP_RUN;
const type = action.actionType
? actionTypeFromJSON(action.actionType)
: ActionType.START_STEP_RUN;
if (type === ActionType.START_STEP_RUN) {
this.handleStartStepRun(action);
} else if (type === ActionType.CANCEL_STEP_RUN) {
Expand Down

0 comments on commit b633f4d

Please sign in to comment.