Skip to content

Commit

Permalink
Merge pull request #85 from kleydon/dev-1
Browse files Browse the repository at this point in the history
Address interval-related errors
  • Loading branch information
kleydon authored May 10, 2022
2 parents 1f6d023 + 17976c8 commit 1e4cb7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Three new options were added apart from the work that was already done by [memor

`prisma-session-store` implements all the **required**, **recommended** and **optional** methods of the [express-session](https://github.com/expressjs/session#session-store-implementation) store, plus a few more:

- `startInterval()` and `stopInterval()` methods to start/clear the automatic check for expired.
- `startInterval(onIntervalError?: (err: unknown) => void)` and `stopInterval()` methods to start/clear the automatic check for expired. (The optional `onError()` callback that fires if/when the interval's `prune()` function throws an error.)
- `prune()` that you can use to manually remove only the expired entries from the store.
- `shutdown()` that can be used to stop any intervals and disconnect from prisma.

Expand Down
11 changes: 7 additions & 4 deletions src/lib/prisma-session-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,16 @@ export class PrismaSessionStore<M extends string = 'session'> extends Store {
/**
* Start an interval to prune expired sessions
*/
public startInterval(): void {
public startInterval(onIntervalError?: (err: unknown) => void): void {
const ms = this.options.checkPeriod;

if (typeof ms === 'number' && ms !== 0) {
this.stopInterval();
this.checkInterval = setInterval(() => {
this.prune();
this.checkInterval = setInterval(async () => {
try {
await this.prune();
} catch (err: unknown) {
if (onIntervalError !== undefined) onIntervalError(err);
}
}, Math.floor(ms));
}
}
Expand Down

0 comments on commit 1e4cb7b

Please sign in to comment.