-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
tools.sendEvent
to step tooling to ensure events aren't duplica…
…ted (#100) ## Description Cherry pick's the core commit from #75 to clean up history and conflicts. --------- Co-authored-by: Jack Williams <[email protected]>
- Loading branch information
1 parent
a64decf
commit e8fa158
Showing
13 changed files
with
363 additions
and
144 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
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
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
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { Inngest } from "inngest"; | ||
|
||
export const inngest = new Inngest({ name: "Example App" }); | ||
export const inngest = new Inngest({ | ||
name: "Example App", | ||
eventKey: "test-key-123", | ||
}); |
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,12 @@ | ||
# Sending an Event Example | ||
|
||
This examples demonstrates sending an event within a step function. | ||
|
||
It is triggered by a `demo/send.event` event, and runs a single step to reliably send an event to Inngest. | ||
|
||
```mermaid | ||
graph TD | ||
Inngest -->|demo/send.event| Function | ||
Function --> step1["step.sendEvent('app/my.event.happened')"] | ||
step1 --> ret[Complete] | ||
``` |
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,73 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
import fetch from "cross-fetch"; | ||
import { | ||
eventRunWithName, | ||
introspectionSchema, | ||
receivedEventWithName, | ||
runHasTimeline, | ||
sendEvent, | ||
} from "../../test/helpers"; | ||
|
||
describe("introspection", () => { | ||
const specs = [ | ||
{ label: "SDK UI", url: "http://127.0.0.1:3000/api/inngest?introspect" }, | ||
{ label: "Dev server UI", url: "http://localhost:8288/dev" }, | ||
]; | ||
|
||
specs.forEach(({ label, url }) => { | ||
test(`should show registered functions in ${label}`, async () => { | ||
const res = await fetch(url); | ||
const data = introspectionSchema.parse(await res.json()); | ||
|
||
expect(data.functions).toContainEqual({ | ||
name: "Send event", | ||
id: expect.stringMatching(/^.*-send-event$/), | ||
triggers: [{ event: "demo/send.event" }], | ||
steps: { | ||
step: { | ||
id: "step", | ||
name: "step", | ||
runtime: { | ||
type: "http", | ||
url: expect.stringMatching( | ||
/^http.+\?fnId=.+-send-event&stepId=step$/ | ||
), | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("run", () => { | ||
let eventId: string; | ||
let runId: string; | ||
|
||
beforeAll(async () => { | ||
eventId = await sendEvent("demo/send.event"); | ||
}); | ||
|
||
test("runs in response to 'demo/send.event'", async () => { | ||
runId = await eventRunWithName(eventId, "Send event"); | ||
expect(runId).toEqual(expect.any(String)); | ||
}); | ||
|
||
test("ran Step 'app/my.event.happened'", async () => { | ||
await expect( | ||
runHasTimeline(runId, { | ||
__typename: "StepEvent", | ||
stepType: "COMPLETED", | ||
name: "app/my.event.happened", | ||
}) | ||
).resolves.toBeDefined(); | ||
}); | ||
|
||
test("sent event 'app/my.event.happened'", async () => { | ||
const event = await receivedEventWithName("app/my.event.happened"); | ||
expect(event).toBeDefined(); | ||
expect(JSON.parse(event?.payload ?? {})).toMatchObject({ foo: "bar" }); | ||
}); | ||
}); |
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,9 @@ | ||
import { inngest } from "../client"; | ||
|
||
export default inngest.createFunction( | ||
{ name: "Send event" }, | ||
"demo/send.event", | ||
async ({ step }) => { | ||
await step.sendEvent("app/my.event.happened", { data: { foo: "bar" } }); | ||
} | ||
); |
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.