diff --git a/README.md b/README.md index 642924c..66bdf98 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,12 @@ async function readme() { console.log(`received job ${job.id} with data ${JSON.stringify(job.data)}`) }) } + +readme() + .catch(err => { + console.log(err) + process.exit(1) + }) ``` pg-boss is a job queue built in Node.js on top of PostgreSQL in order to provide background processing and reliable asynchronous execution to Node.js applications. diff --git a/package-lock.json b/package-lock.json index 69eb2fa..3fb24db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pg-boss", - "version": "10.0.3", + "version": "10.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pg-boss", - "version": "10.0.3", + "version": "10.0.4", "license": "MIT", "dependencies": { "cron-parser": "^4.0.0", diff --git a/package.json b/package.json index 06bec81..44f31c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pg-boss", - "version": "10.0.3", + "version": "10.0.4", "description": "Queueing jobs in Postgres from Node.js like a boss", "main": "./src/index.js", "engines": { diff --git a/src/plans.js b/src/plans.js index 24f3a85..3ff342c 100644 --- a/src/plans.js +++ b/src/plans.js @@ -226,8 +226,10 @@ function createQueueFunction (schema) { $$ DECLARE table_name varchar := 'j' || encode(sha224(queue_name::bytea), 'hex'); + queue_created_on timestamptz; BEGIN + WITH q as ( INSERT INTO ${schema}.queue ( name, policy, @@ -249,7 +251,15 @@ function createQueueFunction (schema) { (options->>'retentionMinutes')::int, options->>'deadLetter', table_name - ); + ) + ON CONFLICT DO NOTHING + RETURNING created_on + ) + SELECT created_on into queue_created_on from q; + + IF queue_created_on IS NULL THEN + RETURN; + END IF; EXECUTE format('CREATE TABLE ${schema}.%I (LIKE ${schema}.job INCLUDING DEFAULTS)', table_name); diff --git a/test/queueTest.js b/test/queueTest.js index e4e97c3..62504f4 100644 --- a/test/queueTest.js +++ b/test/queueTest.js @@ -9,6 +9,14 @@ describe('queues', function () { await boss.createQueue(queue) }) + it('createQueue should work if queue already exists', async function () { + const boss = this.test.boss = await helper.start({ ...this.test.bossConfig, noDefault: true }) + const queue = this.test.bossConfig.schema + + await boss.createQueue(queue) + await boss.createQueue(queue) + }) + it('should reject a queue with invalid characters', async function () { const boss = this.test.boss = await helper.start({ ...this.test.bossConfig, noDefault: true }) const queue = `*${this.test.bossConfig.schema}` diff --git a/test/readme.js b/test/readme.js index d132b67..1b200bd 100644 --- a/test/readme.js +++ b/test/readme.js @@ -11,7 +11,6 @@ async function readme () { const queue = 'readme-queue' - await boss.deleteQueue(queue) await boss.createQueue(queue) const id = await boss.send(queue, { arg1: 'read me' }) @@ -27,3 +26,7 @@ async function readme () { } readme() + .catch(err => { + console.log(err) + process.exit(1) + })