-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve clarity of client methods and improve pg & mongodb clients pe…
…rformance by skipping already processed or 'unready' events
- Loading branch information
1 parent
a99d56e
commit 49c5922
Showing
10 changed files
with
141 additions
and
92 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,67 @@ | ||
import { Client } from "pg"; | ||
import { EventProcessor } from "../../src/processor"; | ||
import { createProcessorClient } from "../../src/pg/client"; | ||
import { migrate, type EventType } from "./index"; | ||
import dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
let processor: ReturnType<typeof EventProcessor> | undefined = undefined; | ||
|
||
(async () => { | ||
const client = new Client({ | ||
user: process.env.POSTGRES_USER, | ||
password: process.env.POSTGRES_PASSWORD, | ||
database: process.env.POSTGRES_DB, | ||
}); | ||
await client.connect(); | ||
await migrate(client); | ||
|
||
processor = EventProcessor( | ||
createProcessorClient<EventType>(client), | ||
{ | ||
ResourceSaved: { | ||
thing1: async (event) => { | ||
console.log(`${event.id} thing1 ${event.correlation_id}`); | ||
if (Math.random() > 0.9) throw new Error("some issue"); | ||
|
||
return; | ||
}, | ||
thing2: async (event) => { | ||
console.log(`${event.id} thing2 ${event.correlation_id}`); | ||
if (Math.random() > 0.9) throw new Error("some issue"); | ||
|
||
return; | ||
}, | ||
thing3: async (event) => { | ||
console.log(`${event.id} thing3 ${event.correlation_id}`); | ||
if (Math.random() > 0.75) throw new Error("some issue"); | ||
|
||
return; | ||
}, | ||
}, | ||
}, | ||
{ sleepTimeMs: 5000, logger: console }, | ||
); | ||
processor.start(); | ||
})(); | ||
|
||
const shutdown = (() => { | ||
let shutdownStarted = false; | ||
return () => { | ||
if (shutdownStarted) return; | ||
|
||
shutdownStarted = true; | ||
|
||
processor | ||
?.stop() | ||
.then(() => { | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
}; | ||
})(); | ||
process.once("SIGTERM", shutdown); | ||
process.once("SIGINT", shutdown); |
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
Oops, something went wrong.