pg-boss 11.1.2 → 12.0.0-beta2
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/dist/index.cjs +2 -0
- package/dist/index.d.mts +270 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2350 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +49 -18
- package/src/attorney.js +0 -258
- package/src/boss.js +0 -158
- package/src/contractor.js +0 -99
- package/src/db.js +0 -50
- package/src/index.js +0 -211
- package/src/manager.js +0 -697
- package/src/migrationStore.js +0 -155
- package/src/plans.js +0 -1017
- package/src/timekeeper.js +0 -203
- package/src/tools.js +0 -60
- package/src/worker.js +0 -99
- package/types.d.ts +0 -323
- package/version.json +0 -3
package/src/migrationStore.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
const assert = require('node:assert')
|
|
2
|
-
const plans = require('./plans')
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
rollback,
|
|
6
|
-
next,
|
|
7
|
-
migrate,
|
|
8
|
-
getAll
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function flatten (schema, commands, version) {
|
|
12
|
-
commands.unshift(plans.assertMigration(schema, version))
|
|
13
|
-
commands.push(plans.setVersion(schema, version))
|
|
14
|
-
|
|
15
|
-
return plans.locked(schema, commands)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function rollback (schema, version, migrations) {
|
|
19
|
-
migrations = migrations || getAll(schema)
|
|
20
|
-
|
|
21
|
-
const result = migrations.find(i => i.version === version)
|
|
22
|
-
|
|
23
|
-
assert(result, `Version ${version} not found.`)
|
|
24
|
-
|
|
25
|
-
return flatten(schema, result.uninstall || [], result.previous)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function next (schema, version, migrations) {
|
|
29
|
-
migrations = migrations || getAll(schema)
|
|
30
|
-
|
|
31
|
-
const result = migrations.find(i => i.previous === version)
|
|
32
|
-
|
|
33
|
-
assert(result, `Version ${version} not found.`)
|
|
34
|
-
|
|
35
|
-
return flatten(schema, result.install, result.version)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function migrate (value, version, migrations) {
|
|
39
|
-
let schema, config
|
|
40
|
-
|
|
41
|
-
if (typeof value === 'string') {
|
|
42
|
-
config = null
|
|
43
|
-
schema = value
|
|
44
|
-
} else {
|
|
45
|
-
config = value
|
|
46
|
-
schema = config.schema
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
migrations = migrations || getAll(schema, config)
|
|
50
|
-
|
|
51
|
-
const result = migrations
|
|
52
|
-
.filter(i => i.previous >= version)
|
|
53
|
-
.sort((a, b) => a.version - b.version)
|
|
54
|
-
.reduce((acc, i) => {
|
|
55
|
-
acc.install = acc.install.concat(i.install)
|
|
56
|
-
acc.version = i.version
|
|
57
|
-
return acc
|
|
58
|
-
}, { install: [], version })
|
|
59
|
-
|
|
60
|
-
assert(result.install.length > 0, `Version ${version} not found.`)
|
|
61
|
-
|
|
62
|
-
return flatten(schema, result.install, result.version)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function getAll (schema) {
|
|
66
|
-
return [
|
|
67
|
-
{
|
|
68
|
-
release: '11.1.0',
|
|
69
|
-
version: 26,
|
|
70
|
-
previous: 25,
|
|
71
|
-
install: [
|
|
72
|
-
`
|
|
73
|
-
CREATE OR REPLACE FUNCTION ${schema}.create_queue(queue_name text, options jsonb)
|
|
74
|
-
RETURNS VOID AS
|
|
75
|
-
$$
|
|
76
|
-
DECLARE
|
|
77
|
-
tablename varchar := CASE WHEN options->>'partition' = 'true'
|
|
78
|
-
THEN 'j' || encode(sha224(queue_name::bytea), 'hex')
|
|
79
|
-
ELSE 'job_common'
|
|
80
|
-
END;
|
|
81
|
-
queue_created_on timestamptz;
|
|
82
|
-
BEGIN
|
|
83
|
-
|
|
84
|
-
WITH q as (
|
|
85
|
-
INSERT INTO ${schema}.queue (
|
|
86
|
-
name,
|
|
87
|
-
policy,
|
|
88
|
-
retry_limit,
|
|
89
|
-
retry_delay,
|
|
90
|
-
retry_backoff,
|
|
91
|
-
retry_delay_max,
|
|
92
|
-
expire_seconds,
|
|
93
|
-
retention_seconds,
|
|
94
|
-
deletion_seconds,
|
|
95
|
-
warning_queued,
|
|
96
|
-
dead_letter,
|
|
97
|
-
partition,
|
|
98
|
-
table_name
|
|
99
|
-
)
|
|
100
|
-
VALUES (
|
|
101
|
-
queue_name,
|
|
102
|
-
options->>'policy',
|
|
103
|
-
COALESCE((options->>'retryLimit')::int, 2),
|
|
104
|
-
COALESCE((options->>'retryDelay')::int, 0),
|
|
105
|
-
COALESCE((options->>'retryBackoff')::bool, false),
|
|
106
|
-
(options->>'retryDelayMax')::int,
|
|
107
|
-
COALESCE((options->>'expireInSeconds')::int, 900),
|
|
108
|
-
COALESCE((options->>'retentionSeconds')::int, 1209600),
|
|
109
|
-
COALESCE((options->>'deleteAfterSeconds')::int, 604800),
|
|
110
|
-
COALESCE((options->>'warningQueueSize')::int, 0),
|
|
111
|
-
options->>'deadLetter',
|
|
112
|
-
COALESCE((options->>'partition')::bool, false),
|
|
113
|
-
tablename
|
|
114
|
-
)
|
|
115
|
-
ON CONFLICT DO NOTHING
|
|
116
|
-
RETURNING created_on
|
|
117
|
-
)
|
|
118
|
-
SELECT created_on into queue_created_on from q;
|
|
119
|
-
|
|
120
|
-
IF queue_created_on IS NULL OR options->>'partition' IS DISTINCT FROM 'true' THEN
|
|
121
|
-
RETURN;
|
|
122
|
-
END IF;
|
|
123
|
-
|
|
124
|
-
EXECUTE format('CREATE TABLE ${schema}.%I (LIKE ${schema}.job INCLUDING DEFAULTS)', tablename);
|
|
125
|
-
|
|
126
|
-
EXECUTE format('ALTER TABLE ${schema}.%1$I ADD PRIMARY KEY (name, id)', tablename);
|
|
127
|
-
EXECUTE format('ALTER TABLE ${schema}.%1$I ADD CONSTRAINT q_fkey FOREIGN KEY (name) REFERENCES ${schema}.queue (name) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED', tablename);
|
|
128
|
-
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', tablename);
|
|
129
|
-
|
|
130
|
-
EXECUTE format('CREATE INDEX %1$s_i5 ON ${schema}.%1$I (name, start_after) INCLUDE (priority, created_on, id) WHERE state < ''active''', tablename);
|
|
131
|
-
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', tablename);
|
|
132
|
-
|
|
133
|
-
IF options->>'policy' = 'short' THEN
|
|
134
|
-
EXECUTE format('CREATE UNIQUE INDEX %1$s_i1 ON ${schema}.%1$I (name, COALESCE(singleton_key, '''')) WHERE state = ''created'' AND policy = ''short''', tablename);
|
|
135
|
-
ELSIF options->>'policy' = 'singleton' THEN
|
|
136
|
-
EXECUTE format('CREATE UNIQUE INDEX %1$s_i2 ON ${schema}.%1$I (name, COALESCE(singleton_key, '''')) WHERE state = ''active'' AND policy = ''singleton''', tablename);
|
|
137
|
-
ELSIF options->>'policy' = 'stately' THEN
|
|
138
|
-
EXECUTE format('CREATE UNIQUE INDEX %1$s_i3 ON ${schema}.%1$I (name, state, COALESCE(singleton_key, '''')) WHERE state <= ''active'' AND policy = ''stately''', tablename);
|
|
139
|
-
ELSIF options->>'policy' = 'exclusive' THEN
|
|
140
|
-
EXECUTE format('CREATE UNIQUE INDEX %1$s_i6 ON ${schema}.%1$I (name, COALESCE(singleton_key, '''')) WHERE state <= ''active'' AND policy = ''exclusive''', tablename);
|
|
141
|
-
END IF;
|
|
142
|
-
|
|
143
|
-
EXECUTE format('ALTER TABLE ${schema}.%I ADD CONSTRAINT cjc CHECK (name=%L)', tablename, queue_name);
|
|
144
|
-
EXECUTE format('ALTER TABLE ${schema}.job ATTACH PARTITION ${schema}.%I FOR VALUES IN (%L)', tablename, queue_name);
|
|
145
|
-
END;
|
|
146
|
-
$$
|
|
147
|
-
LANGUAGE plpgsql;
|
|
148
|
-
`,
|
|
149
|
-
`CREATE UNIQUE INDEX job_i6 ON ${schema}.job_common (name, COALESCE(singleton_key, '')) WHERE state <= 'active' AND policy = 'exclusive'`
|
|
150
|
-
],
|
|
151
|
-
uninstall: [
|
|
152
|
-
`DROP INDEX ${schema}.job_i6`
|
|
153
|
-
]
|
|
154
|
-
},]
|
|
155
|
-
}
|