-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webhooks): add webhook workflows
- Loading branch information
Showing
11 changed files
with
738 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { createServer } from 'node:http'; | ||
import { Workflow, Worker } from '../src'; | ||
import sleep from '../src/util/sleep'; | ||
import Hatchet from '../src/sdk'; | ||
|
||
const port = 8369; | ||
|
||
describe('e2e', () => { | ||
let hatchet: Hatchet; | ||
let worker: Worker; | ||
|
||
beforeEach(async () => { | ||
hatchet = Hatchet.init(); | ||
worker = await hatchet.worker('simple-webhook-workflow'); | ||
}); | ||
|
||
afterEach(async () => { | ||
await worker.stop(); | ||
await sleep(2000); | ||
}); | ||
|
||
it('should pass a simple workflow', async () => { | ||
let invoked = 0; | ||
|
||
const workflow: Workflow = { | ||
id: 'simple-webhook-workflow', | ||
webhook: `http://localhost:${port}/webhook`, | ||
description: 'test', | ||
on: { | ||
event: 'user:create-webhook', | ||
}, | ||
steps: [ | ||
{ | ||
name: 'step1', | ||
run: async (ctx) => { | ||
console.log('invoked!! ✅✅✅✅✅✅✅'); | ||
console.log('invoked!! ✅✅✅✅✅✅✅'); | ||
console.log('invoked!! ✅✅✅✅✅✅✅'); | ||
console.log('invoked!! ✅✅✅✅✅✅✅'); | ||
console.log('invoked!! ✅✅✅✅✅✅✅'); | ||
invoked += 1; | ||
return { message: `${ctx.workflowName()} results!` }; | ||
}, | ||
}, | ||
{ | ||
name: 'step2', | ||
parents: ['step1'], | ||
run: (ctx) => { | ||
invoked += 1; | ||
return { message: `${ctx.workflowName()} results!` }; | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
console.log('registering workflow...'); | ||
await worker.registerWorkflow(workflow); | ||
|
||
const secret = 'secret'; | ||
const server = createServer(await worker.handler(secret)); | ||
|
||
await new Promise((resolve) => { | ||
server.listen(port, () => { | ||
resolve(''); | ||
}); | ||
}); | ||
|
||
console.log('worker started.'); | ||
|
||
await sleep(5000); | ||
|
||
console.log('pushing event...'); | ||
|
||
await hatchet.event.push('user:create-webhook', { | ||
test: 'test', | ||
}); | ||
|
||
await sleep(10000); | ||
|
||
console.log('invoked', invoked); | ||
|
||
expect(invoked).toEqual(2); | ||
|
||
await worker.stop(); | ||
}, 60000); | ||
}); |
Submodule hatchet
updated
65 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.