timgit / pg-boss

Queueing jobs in Postgres from Node.js like a boss
MIT License
2.15k stars 160 forks source link

Weird tables and dead letter #494

Closed masylum closed 1 month ago

masylum commented 2 months ago

Just a quick question. Why do some random tables show up?

CleanShot 2024-09-20 at 16 09 15

And also, how does the dead_letter option work? When I set it up it complains about a foreign key.

insert or update on table "j4777edf56ffde3bf9825a30e48fec7ca13c3e0c094ff2ac924e98563" violates foreign key constraint "dlq_fkey"


    const boss = new PgBoss(dbURL)

    boss.on('error', logger.error)
    await boss.start()

    await boss.createQueue(QUEUES.hourlySubscription)
    await boss.createQueue(QUEUES.adjustUser)

    await boss.work(QUEUES.hourlySubscription, async () => {
        try {
            const u = await db.select().from(users)

            for (const user of u) {
                await boss.send(
                    QUEUES.adjustUser,
                    { userId: user.id },
                    {
                        retryLimit: 3,
                        retryDelay: 20,
                        retryBackoff: true,
                        expireInMinutes: 5,
                        deadLetter: `hourlySubscription-${user.id}`,
                    },
                )
            }
        } catch (e) {
            logger.error(e)
            throw e
        }
    })

  await boss.work(QUEUES.adjustUser, async ([job]) => {
    // ...
  })

    await boss.send(QUEUES.hourlySubscription, {})
timgit commented 2 months ago

Those tables are partitions of the job table. Dead letter queues have to be created first like normal queues.

masylum commented 1 month ago

Ok, so I basically shouldn't worry about those tables showing up and I should create dead letter queues beforehand. Got it! Thanks