Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I do not see a graceful disconnect in the express example #7263

Open
jared-dahlke-dexcom opened this issue Dec 18, 2024 · 0 comments
Open

I do not see a graceful disconnect in the express example #7263

jared-dahlke-dexcom opened this issue Dec 18, 2024 · 0 comments

Comments

@jared-dahlke-dexcom
Copy link

I'm doing this in my express app to gracefully disconnect from postgres. Is this not better? I don't see anything like this in your express example unless I'm missing it:

...other code

import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();

const gracefulPrismaPostgresShutdown = async () => {
    console.log("Shutting down prisma postgres connection gracefully...");
    await prisma.$disconnect();
    process.exit(0);
};
// Handle termination signals
process.on("SIGINT", gracefulPrismaPostgresShutdown);
process.on("SIGTERM", gracefulPrismaPostgresShutdown);

app.use(async (err, req, res, next) => {
    if (err) {
        console.error("Unhandled error:", err);
        await prisma.$disconnect(); // Ensure disconnect
        respondError(res, err ?? "Technical Error");
    }
    next();
});

// Set up global middleware
app.use(cors(), express.json(), authenticateJWT);

/**
 * ROUTES
 */

// Get all subscriptions
app.get("/subscriptions", (req, res, next) => {
    subscriptionsGet(req, res, next);
});


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant