Skip to content

Commit

Permalink
fix: async examples
Browse files Browse the repository at this point in the history
  • Loading branch information
grutt committed Feb 3, 2024
1 parent b1e9bf0 commit 4640e62
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 17 deletions.
7 changes: 7 additions & 0 deletions typescript-sdk/examples/concurrency/concurrency-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Hatchet from '../../src/sdk';

const hatchet = Hatchet.init();

hatchet.event.push('concurrency:create', {
test: 'test',
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Hatchet from '../src/sdk';
import { Workflow } from '../src/workflow';
import Hatchet from '../../src/sdk';
import { Workflow } from '../../src/workflow';

const hatchet = Hatchet.init();

Expand All @@ -9,10 +9,10 @@ const sleep = (ms: number) =>
});

const workflow: Workflow = {
id: 'example',
id: 'concurrency-example',
description: 'test',
on: {
event: 'user:create',
event: 'concurrency:create',
},
concurrency: {
key: (ctx) => ctx.workflowInput().userId,
Expand All @@ -38,6 +38,10 @@ const workflow: Workflow = {
],
};

const worker = hatchet.worker('example-worker');
worker.registerWorkflow(workflow);
worker.start();
async function main() {
const worker = await hatchet.worker('example-worker');
await worker.registerWorkflow(workflow);
worker.start();
}

main();
10 changes: 7 additions & 3 deletions typescript-sdk/examples/dag-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const workflow: Workflow = {
],
};

const worker = hatchet.worker('example-worker');
worker.registerWorkflow(workflow);
worker.start();
async function main() {
const worker = await hatchet.worker('example-worker');
await worker.registerWorkflow(workflow);
worker.start();
}

main();
10 changes: 7 additions & 3 deletions typescript-sdk/examples/simple-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const workflow: Workflow = {
],
};

const worker = hatchet.worker('example-worker');
worker.registerWorkflow(workflow);
worker.start();
async function main() {
const worker = await hatchet.worker('example-worker');
await worker.registerWorkflow(workflow);
worker.start();
}

main();
3 changes: 2 additions & 1 deletion typescript-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"example:event": "npm run exec -- ./examples/example-event.ts",
"worker:simple": "npm run exec -- ./examples/simple-worker.ts",
"worker:dag": "npm run exec -- ./examples/dag-worker.ts",
"worker:concurrency": "npm run exec -- ./examples/concurrency-worker.ts"
"worker:concurrency": "npm run exec -- ./examples/concurrency/concurrency-worker.ts",
"event:concurrency": "npm run exec -- ./examples/concurrency/concurrency-event.ts"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 2 additions & 2 deletions typescript-sdk/src/clients/hatchet-client/hatchet-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ export class HatchetClient {
return worker;
}

worker(workflow: string | Workflow): Worker {
async worker(workflow: string | Workflow): Promise<Worker> {
const name = typeof workflow === 'string' ? workflow : workflow.id;
const worker = new Worker(this, {
name,
});

if (typeof workflow !== 'string') {
worker.registerWorkflow(workflow);
await worker.registerWorkflow(workflow);
return worker;
}

Expand Down
2 changes: 1 addition & 1 deletion typescript-sdk/src/clients/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Worker {
this.logger = new Logger(`Worker/${this.name}`, this.client.config.log_level);
}

async registerWorkflow(workflow: Workflow, options?: { autoVersion?: boolean }) {
async registerWorkflow(workflow: Workflow) {
try {
const concurrency: WorkflowConcurrencyOpts | undefined = undefined;

Expand Down

0 comments on commit 4640e62

Please sign in to comment.