Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Understanding postgres.js connection management in Trigger.dev v3 #2218

Unanswered
leedia-tech asked this question in Q&A
Discussion options

I'm using postgres.js and noticed your Drizzle example creates the db instance outside the task.

I'm wondering:

  1. Task isolation: Do tasks run in separate workers/processes, or share the same Node process?

  2. Connection lifecycle: If I create a postgres instance outside the task:

    const sql = postgres(process.env.DATABASE_URL!)
    export const myTask = task({
     id: "my-task",
     run: async (payload) => {
     return sql`SELECT * FROM users`
     }
    })

    Is this instance shared across all executions, or does each worker get its own?

  3. Connection cleanup: postgres.js requires sql.end() to properly close connections. Should I handle this cleanup or does the worker lifecycle manage it?

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /