pg-boss 10.1.4 → 10.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-boss",
3
- "version": "10.1.4",
3
+ "version": "10.1.6",
4
4
  "description": "Queueing jobs in Postgres from Node.js like a boss",
5
5
  "main": "./src/index.js",
6
6
  "engines": {
@@ -23,7 +23,8 @@
23
23
  "cover": "nyc npm test",
24
24
  "tsc": "tsc --noEmit types.d.ts",
25
25
  "readme": "node ./test/readme.js",
26
- "migrate": "node -e 'console.log(require(\"./src\").getMigrationPlans())'"
26
+ "db:migrate": "node -e 'console.log(require(\"./src\").getMigrationPlans())'",
27
+ "db:construct": "node -e 'console.log(require(\"./src\").getConstructionPlans())'"
27
28
  },
28
29
  "mocha": {
29
30
  "timeout": 10000,
@@ -64,6 +64,72 @@ function migrate (value, version, migrations) {
64
64
 
65
65
  function getAll (schema) {
66
66
  return [
67
+ {
68
+ release: '10.1.5',
69
+ version: 24,
70
+ previous: 23,
71
+ install: [
72
+ `
73
+ CREATE OR REPLACE FUNCTION ${schema}.create_queue(queue_name text, options json)
74
+ RETURNS VOID AS
75
+ $$
76
+ DECLARE
77
+ table_name varchar := 'j' || encode(sha224(queue_name::bytea), 'hex');
78
+ queue_created_on timestamptz;
79
+ BEGIN
80
+
81
+ WITH q as (
82
+ INSERT INTO ${schema}.queue (
83
+ name,
84
+ policy,
85
+ retry_limit,
86
+ retry_delay,
87
+ retry_backoff,
88
+ expire_seconds,
89
+ retention_minutes,
90
+ dead_letter,
91
+ partition_name
92
+ )
93
+ VALUES (
94
+ queue_name,
95
+ options->>'policy',
96
+ (options->>'retryLimit')::int,
97
+ (options->>'retryDelay')::int,
98
+ (options->>'retryBackoff')::bool,
99
+ (options->>'expireInSeconds')::int,
100
+ (options->>'retentionMinutes')::int,
101
+ options->>'deadLetter',
102
+ table_name
103
+ )
104
+ ON CONFLICT DO NOTHING
105
+ RETURNING created_on
106
+ )
107
+ SELECT created_on into queue_created_on from q;
108
+
109
+ IF queue_created_on IS NULL THEN
110
+ RETURN;
111
+ END IF;
112
+
113
+ EXECUTE format('CREATE TABLE ${schema}.%I (LIKE ${schema}.job INCLUDING DEFAULTS)', table_name);
114
+
115
+ EXECUTE format('ALTER TABLE ${schema}.%1$I ADD PRIMARY KEY (name, id)', table_name);
116
+ 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);
117
+ 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);
118
+ EXECUTE format('CREATE UNIQUE INDEX %1$s_i1 ON ${schema}.%1$I (name, COALESCE(singleton_key, '''')) WHERE state = ''created'' AND policy = ''short''', table_name);
119
+ EXECUTE format('CREATE UNIQUE INDEX %1$s_i2 ON ${schema}.%1$I (name, COALESCE(singleton_key, '''')) WHERE state = ''active'' AND policy = ''singleton''', table_name);
120
+ 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);
121
+ 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);
122
+ EXECUTE format('CREATE INDEX %1$s_i5 ON ${schema}.%1$I (name, start_after) INCLUDE (priority, created_on, id) WHERE state < ''active''', table_name);
123
+
124
+ EXECUTE format('ALTER TABLE ${schema}.%I ADD CONSTRAINT cjc CHECK (name=%L)', table_name, queue_name);
125
+ EXECUTE format('ALTER TABLE ${schema}.job ATTACH PARTITION ${schema}.%I FOR VALUES IN (%L)', table_name, queue_name);
126
+ END;
127
+ $$
128
+ LANGUAGE plpgsql
129
+ `
130
+ ],
131
+ uninstall: []
132
+ },
67
133
  {
68
134
  release: '10.1.1',
69
135
  version: 23,
package/src/plans.js CHANGED
@@ -332,7 +332,7 @@ function createPrimaryKeyArchive (schema) {
332
332
  }
333
333
 
334
334
  function createIndexJobPolicyShort (schema) {
335
- return `CREATE UNIQUE INDEX job_i1 ON ${schema}.job (name, COALESCE(singleton_key, '')) WHERE state = '${JOB_STATES.created}' AND policy = '${QUEUE_POLICIES.short}';`
335
+ return `CREATE UNIQUE INDEX job_i1 ON ${schema}.job (name, COALESCE(singleton_key, '')) WHERE state = '${JOB_STATES.created}' AND policy = '${QUEUE_POLICIES.short}'`
336
336
  }
337
337
 
338
338
  function createIndexJobPolicySingleton (schema) {
package/src/timekeeper.js CHANGED
@@ -144,7 +144,7 @@ class Timekeeper extends EventEmitter {
144
144
  const scheduled = schedules
145
145
  .filter(i => this.shouldSendIt(i.cron, i.timezone))
146
146
  .map(({ name, data, options }) =>
147
- ({ name: QUEUES.SEND_IT, data: { name, data, options }, singletonKey: name, singletonSeconds: 60 }))
147
+ ({ name: QUEUES.SEND_IT, data: { name, data, ...options }, singletonKey: name, singletonSeconds: 60 }))
148
148
 
149
149
  if (scheduled.length > 0 && !this.stopped) {
150
150
  await this.manager.insert(scheduled)
package/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "schema": 23
2
+ "schema": 24
3
3
  }