Skip to content

Commit

Permalink
Merge branch 'master' into v11
Browse files Browse the repository at this point in the history
  • Loading branch information
timgit committed Dec 5, 2024
2 parents 91d78a4 + 57b74cc commit b049eda
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/api/workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The default options for `work()` is 1 job every 2 seconds.

Same as in [`fetch()`](#fetch)

* **includeMetadata**, bool, *(default=true)*
* **includeMetadata**, bool, *(default=false)*

Same as in [`fetch()`](#fetch)

Expand Down
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
search: 'auto',
loadSidebar: true,
subMaxLevel: 3,
auto2top: true,
name: 'pg-boss',
repo: 'https://github.com/timgit/pg-boss',
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-boss",
"version": "10.1.4",
"version": "10.1.5",
"description": "Queueing jobs in Postgres from Node.js like a boss",
"main": "./src/index.js",
"engines": {
Expand All @@ -23,7 +23,8 @@
"cover": "nyc npm test",
"tsc": "tsc --noEmit types.d.ts",
"readme": "node ./test/readme.js",
"migrate": "node -e 'console.log(require(\"./src\").getMigrationPlans())'"
"db:migrate": "node -e 'console.log(require(\"./src\").getMigrationPlans())'",
"db:construct": "node -e 'console.log(require(\"./src\").getConstructionPlans())'"
},
"mocha": {
"timeout": 10000,
Expand Down
66 changes: 66 additions & 0 deletions src/migrationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,72 @@ function migrate (value, version, migrations) {

function getAll (schema) {
return [
{
release: '10.1.5',
version: 24,
previous: 23,
install: [
`
CREATE OR REPLACE FUNCTION ${schema}.create_queue(queue_name text, options json)
RETURNS VOID AS
$$
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,
retry_limit,
retry_delay,
retry_backoff,
expire_seconds,
retention_minutes,
dead_letter,
partition_name
)
VALUES (
queue_name,
options->>'policy',
(options->>'retryLimit')::int,
(options->>'retryDelay')::int,
(options->>'retryBackoff')::bool,
(options->>'expireInSeconds')::int,
(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);
EXECUTE format('ALTER TABLE ${schema}.%1$I ADD PRIMARY KEY (name, id)', table_name);
EXECUTE format('ALTER TABLE ${schema}.%1$I ADD CONSTRAINT q_fkey FOREIGN KEY (name) REFERENCES ${schema}.queue (name) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED', table_name);
EXECUTE format('ALTER TABLE ${schema}.%1$I ADD CONSTRAINT dlq_fkey FOREIGN KEY (dead_letter) REFERENCES ${schema}.queue (name) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED', table_name);
EXECUTE format('CREATE UNIQUE INDEX %1$s_i1 ON ${schema}.%1$I (name, COALESCE(singleton_key, '''')) WHERE state = ''created'' AND policy = ''short''', table_name);
EXECUTE format('CREATE UNIQUE INDEX %1$s_i2 ON ${schema}.%1$I (name, COALESCE(singleton_key, '''')) WHERE state = ''active'' AND policy = ''singleton''', table_name);
EXECUTE format('CREATE UNIQUE INDEX %1$s_i3 ON ${schema}.%1$I (name, state, COALESCE(singleton_key, '''')) WHERE state <= ''active'' AND policy = ''stately''', table_name);
EXECUTE format('CREATE UNIQUE INDEX %1$s_i4 ON ${schema}.%1$I (name, singleton_on, COALESCE(singleton_key, '''')) WHERE state <> ''cancelled'' AND singleton_on IS NOT NULL', table_name);
EXECUTE format('CREATE INDEX %1$s_i5 ON ${schema}.%1$I (name, start_after) INCLUDE (priority, created_on, id) WHERE state < ''active''', table_name);
EXECUTE format('ALTER TABLE ${schema}.%I ADD CONSTRAINT cjc CHECK (name=%L)', table_name, queue_name);
EXECUTE format('ALTER TABLE ${schema}.job ATTACH PARTITION ${schema}.%I FOR VALUES IN (%L)', table_name, queue_name);
END;
$$
LANGUAGE plpgsql
`
],
uninstall: []
},
{
release: '10.1.1',
version: 23,
Expand Down
2 changes: 1 addition & 1 deletion src/plans.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ function createQueueForeignKeyJobDeadLetter (schema) {
}

function createIndexJobPolicyShort (schema) {
return `CREATE UNIQUE INDEX job_i1 ON ${schema}.job (name, COALESCE(singleton_key, '')) WHERE state = '${JOB_STATES.created}' AND policy = '${QUEUE_POLICIES.short}';`
return `CREATE UNIQUE INDEX job_i1 ON ${schema}.job (name, COALESCE(singleton_key, '')) WHERE state = '${JOB_STATES.created}' AND policy = '${QUEUE_POLICIES.short}'`
}

function createIndexJobPolicySingleton (schema) {
Expand Down
22 changes: 22 additions & 0 deletions test/scheduleTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ describe('schedule', function () {
assert(job)
})

it('should set job metadata correctly', async function () {
const config = {
...this.test.bossConfig,
cronMonitorIntervalSeconds: 1,
cronWorkerIntervalSeconds: 1,
schedule: true
}

const boss = this.test.boss = await helper.start(config)
const queue = this.test.bossConfig.schema

await boss.schedule(queue, '* * * * *', {}, { retryLimit: 42 })

await delay(4000)

const [job] = await boss.fetch(queue, { includeMetadata: true })

assert(job)

assert.strictEqual(job.retryLimit, 42)
})

it('should fail to schedule a queue that does not exist', async function () {
const boss = this.test.boss = await helper.start({ ...this.test.bossConfig, noDefault: true })
const queue = this.test.bossConfig.schema
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"schema": 23
"schema": 24
}

0 comments on commit b049eda

Please sign in to comment.