-
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.
Overhaul examples for testing and demonstrating patterns
- Loading branch information
1 parent
b0ab085
commit e242f29
Showing
17 changed files
with
103 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Hello World Example | ||
|
||
This demonstrates the simplest possible function. It's triggered by a `demo/hello.world` event and returns `"Hello, Inngest!"`. | ||
|
||
```mermaid | ||
graph TD | ||
Inngest -->|demo/hello.world| Function | ||
Function -->|Returns| Hello[Hello, Inngest!] | ||
``` |
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
4 changes: 2 additions & 2 deletions
4
src/examples/helloWorld.ts → src/examples/hello-world/index.ts
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,7 +1,7 @@ | ||
import { inngest } from "./client"; | ||
import { inngest } from "../client"; | ||
|
||
export default inngest.createFunction( | ||
{ name: "Hello World" }, | ||
{ event: "demo/event.sent" }, | ||
{ event: "demo/hello.world" }, | ||
() => "Hello, Inngest!" | ||
); |
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,17 @@ | ||
# Parallel Reduce Example | ||
|
||
This example demonstrates how to run multiple steps in parallel to accumulate a value using `Array.prototype.reduce`. | ||
|
||
It is triggered by a `demo/parallel.reduce` event, runs three steps in parallel to fetch scores from a database, and accumulates the total of all of the scores. | ||
|
||
To see a sequential version of this pattern, see the [sequential reduce example](/src/examples/sequential-reduce). | ||
|
||
```mermaid | ||
graph TD | ||
Inngest -->|demo/parallel.reduce| Function | ||
Function -->|Run step| blue[Get blue team score] | ||
Function -->|Run step| red[Get red team score] | ||
Function -->|Run step| green[Get green team score] | ||
blue & red & green --> total[Accumulate score] | ||
total -->|Returns| done[150] | ||
``` |
2 changes: 1 addition & 1 deletion
2
src/examples/parallelReduce.ts → src/examples/parallel-reduce/index.ts
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,34 @@ | ||
# Parallel Work Example | ||
|
||
This example demonstrates how to run concurrent chains of work in the same step function, bringing their values together at the end. | ||
|
||
It is triggered by a `demo/parallel.work` event, runs 2 separate chains of work in parallel: `getScore()` and `getFruits()`. | ||
|
||
`getScore()` will run 3 steps sequentially, returning a `number` score. | ||
|
||
`getFruits()` will run 3 steps in parallel, returning an array of fruits. | ||
|
||
Finally, we return the result of these two chains of work at the end of the function. | ||
|
||
```mermaid | ||
graph TD | ||
Inngest -->|demo/parallel.work| Function | ||
subgraph getScore["getScore (sequential)"] | ||
score1[First score] | ||
score1 -->|Run step| score2[Second score] | ||
score2 -->|Run step| score3[Third score] | ||
end | ||
subgraph getFruits["getFruits (parallel)"] | ||
apple[Get apple] | ||
banana[Get banana] | ||
orange[Get orange] | ||
end | ||
Function -->|Run steps| getScore & getFruits | ||
getFruits ----> ret[Accumulate results] | ||
score3 --> ret | ||
ret -->|Returns| done["[ 5, 'Apple, Banana, Orange' ]"] | ||
``` |
2 changes: 1 addition & 1 deletion
2
src/examples/parallelWork.ts → src/examples/parallel-work/index.ts
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/examples/Promise.all.ts → src/examples/promise-all/index.ts
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/examples/Promise.race.ts → src/examples/promise-race/index.ts
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,17 @@ | ||
# Sequential Reduce Example | ||
|
||
This example demonstrates how to run multiple steps in sequence to accumulate a value using `Array.prototype.reduce`. | ||
|
||
It is triggered by a `demo/sequential.reduce` event, runs three steps sequentially to fetch scores from a database, and accumulates the total of all of the scores. | ||
|
||
To see a parallel version of this pattern, see the [parallel reduce example](/src/examples/parallel-reduce). | ||
|
||
```mermaid | ||
graph TD | ||
Inngest -->|demo/sequential.reduce| Function | ||
Function -->|Run step| blue[Get blue team score] | ||
blue -->|Run step| red[Get red team score] | ||
red -->|Run step| green[Get green team score] | ||
green --> total[Accumulate score] | ||
total -->|Returns| done[150] | ||
``` |
2 changes: 1 addition & 1 deletion
2
src/examples/sequentialReduce.ts → src/examples/sequential-reduce/index.ts
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