Skip to content

Commit 9f3cd4a

Browse files
author
Mitchell Amihod
committed
docs: Add link to discussion around the issue in prisma. Expand example with a bit more context on how to implement.
1 parent 06c9af1 commit 9f3cd4a

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

content/recipes/prisma.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class PrismaService extends PrismaClient
260260
}
261261
```
262262

263-
> info **Note** The `onModuleInit` is optional - if you leave it out, Prisma will connect lazily on first call to db. We don't bother with `onModuleDestroy`, since Prisma has its own shutdown hooks where it will destroy the connection.
263+
> info **Note** The `onModuleInit` is optional - if you leave it out, Prisma will connect lazily on first call to db. We don't bother with `onModuleDestroy`, since Prisma has its own shutdown hooks where it will destroy the connection.
264264
265265
Next, you can write services that you can use to make database calls for the `User` and `Post` models from your Prisma schema.
266266

@@ -517,14 +517,26 @@ This controller implements the following routes:
517517

518518
#### Issues with `enableShutdownHooks`
519519

520-
Prisma interferes with NestJS `enableShutdownHooks` - Prisma listens for shutdown signals and will call process.exit() before your application shutdown hooks fire. To deal with this, you would need to add a listener for Prisma `beforeExit` event.
520+
Prisma interferes with NestJS `enableShutdownHooks`. Prisma listens for shutdown signals and will call process.exit() before your application shutdown hooks fire. To deal with this, you would need to add a listener for Prisma `beforeExit` event.
521+
521522
```typescript
522-
prismaService.$on('beforeExit', async () => {
523-
logger.log('Prisma before exit...');
524-
await app.close();
525-
});
523+
// main.ts
524+
...
525+
import { PrismaService } from './services/prisma/prisma.service';
526+
...
527+
bootstrap() {
528+
...
529+
const prismaService: PrismaService = app.get(PrismaService);
530+
531+
prismaService.$on('beforeExit', async () => {
532+
logger.log('Prisma before exit...');
533+
await app.close();
534+
});
535+
...
536+
}
526537
```
527538

539+
You can [read more](https://github.com/prisma/prisma/issues/2917#issuecomment-708340112) about Prisma handling of shutdown signal, and `beforeExit` event.
528540

529541
#### Summary
530542

0 commit comments

Comments
 (0)