pg-boss 12.0.0-beta1 → 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 +5 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +225 -224
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -9
- package/version.json +0 -3
package/dist/index.mjs
CHANGED
|
@@ -39,28 +39,28 @@ const QUEUE_DEFAULTS = {
|
|
|
39
39
|
partition: false
|
|
40
40
|
};
|
|
41
41
|
const COMMON_JOB_TABLE = "job_common";
|
|
42
|
-
function create(schema
|
|
43
|
-
return locked(schema
|
|
44
|
-
createSchema(schema
|
|
45
|
-
createEnumJobState(schema
|
|
46
|
-
createTableVersion(schema
|
|
47
|
-
createTableQueue(schema
|
|
48
|
-
createTableSchedule(schema
|
|
49
|
-
createTableSubscription(schema
|
|
50
|
-
createTableJob(schema
|
|
51
|
-
createPrimaryKeyJob(schema
|
|
52
|
-
createTableJobCommon(schema
|
|
53
|
-
createQueueFunction(schema
|
|
54
|
-
deleteQueueFunction(schema
|
|
55
|
-
insertVersion(schema
|
|
42
|
+
function create(schema, version) {
|
|
43
|
+
return locked(schema, [
|
|
44
|
+
createSchema(schema),
|
|
45
|
+
createEnumJobState(schema),
|
|
46
|
+
createTableVersion(schema),
|
|
47
|
+
createTableQueue(schema),
|
|
48
|
+
createTableSchedule(schema),
|
|
49
|
+
createTableSubscription(schema),
|
|
50
|
+
createTableJob(schema),
|
|
51
|
+
createPrimaryKeyJob(schema),
|
|
52
|
+
createTableJobCommon(schema, COMMON_JOB_TABLE),
|
|
53
|
+
createQueueFunction(schema),
|
|
54
|
+
deleteQueueFunction(schema),
|
|
55
|
+
insertVersion(schema, version)
|
|
56
56
|
]);
|
|
57
57
|
}
|
|
58
|
-
function createSchema(schema
|
|
59
|
-
return `CREATE SCHEMA IF NOT EXISTS ${schema
|
|
58
|
+
function createSchema(schema) {
|
|
59
|
+
return `CREATE SCHEMA IF NOT EXISTS ${schema}`;
|
|
60
60
|
}
|
|
61
|
-
function createEnumJobState(schema
|
|
61
|
+
function createEnumJobState(schema) {
|
|
62
62
|
return `
|
|
63
|
-
CREATE TYPE ${schema
|
|
63
|
+
CREATE TYPE ${schema}.job_state AS ENUM (
|
|
64
64
|
'${JOB_STATES.created}',
|
|
65
65
|
'${JOB_STATES.retry}',
|
|
66
66
|
'${JOB_STATES.active}',
|
|
@@ -70,17 +70,17 @@ function createEnumJobState(schema$1) {
|
|
|
70
70
|
)
|
|
71
71
|
`;
|
|
72
72
|
}
|
|
73
|
-
function createTableVersion(schema
|
|
73
|
+
function createTableVersion(schema) {
|
|
74
74
|
return `
|
|
75
|
-
CREATE TABLE ${schema
|
|
75
|
+
CREATE TABLE ${schema}.version (
|
|
76
76
|
version int primary key,
|
|
77
77
|
cron_on timestamp with time zone
|
|
78
78
|
)
|
|
79
79
|
`;
|
|
80
80
|
}
|
|
81
|
-
function createTableQueue(schema
|
|
81
|
+
function createTableQueue(schema) {
|
|
82
82
|
return `
|
|
83
|
-
CREATE TABLE ${schema
|
|
83
|
+
CREATE TABLE ${schema}.queue (
|
|
84
84
|
name text NOT NULL,
|
|
85
85
|
policy text NOT NULL,
|
|
86
86
|
retry_limit int NOT NULL,
|
|
@@ -90,7 +90,7 @@ function createTableQueue(schema$1) {
|
|
|
90
90
|
expire_seconds int NOT NULL,
|
|
91
91
|
retention_seconds int NOT NULL,
|
|
92
92
|
deletion_seconds int NOT NULL,
|
|
93
|
-
dead_letter text REFERENCES ${schema
|
|
93
|
+
dead_letter text REFERENCES ${schema}.queue (name) CHECK (dead_letter IS DISTINCT FROM name),
|
|
94
94
|
partition bool NOT NULL,
|
|
95
95
|
table_name text NOT NULL,
|
|
96
96
|
deferred_count int NOT NULL default 0,
|
|
@@ -107,10 +107,10 @@ function createTableQueue(schema$1) {
|
|
|
107
107
|
)
|
|
108
108
|
`;
|
|
109
109
|
}
|
|
110
|
-
function createTableSchedule(schema
|
|
110
|
+
function createTableSchedule(schema) {
|
|
111
111
|
return `
|
|
112
|
-
CREATE TABLE ${schema
|
|
113
|
-
name text REFERENCES ${schema
|
|
112
|
+
CREATE TABLE ${schema}.schedule (
|
|
113
|
+
name text REFERENCES ${schema}.queue ON DELETE CASCADE,
|
|
114
114
|
key text not null DEFAULT '',
|
|
115
115
|
cron text not null,
|
|
116
116
|
timezone text,
|
|
@@ -122,25 +122,25 @@ function createTableSchedule(schema$1) {
|
|
|
122
122
|
)
|
|
123
123
|
`;
|
|
124
124
|
}
|
|
125
|
-
function createTableSubscription(schema
|
|
125
|
+
function createTableSubscription(schema) {
|
|
126
126
|
return `
|
|
127
|
-
CREATE TABLE ${schema
|
|
127
|
+
CREATE TABLE ${schema}.subscription (
|
|
128
128
|
event text not null,
|
|
129
|
-
name text not null REFERENCES ${schema
|
|
129
|
+
name text not null REFERENCES ${schema}.queue ON DELETE CASCADE,
|
|
130
130
|
created_on timestamp with time zone not null default now(),
|
|
131
131
|
updated_on timestamp with time zone not null default now(),
|
|
132
132
|
PRIMARY KEY(event, name)
|
|
133
133
|
)
|
|
134
134
|
`;
|
|
135
135
|
}
|
|
136
|
-
function createTableJob(schema
|
|
136
|
+
function createTableJob(schema) {
|
|
137
137
|
return `
|
|
138
|
-
CREATE TABLE ${schema
|
|
138
|
+
CREATE TABLE ${schema}.job (
|
|
139
139
|
id uuid not null default gen_random_uuid(),
|
|
140
140
|
name text not null,
|
|
141
141
|
priority integer not null default(0),
|
|
142
142
|
data jsonb,
|
|
143
|
-
state ${schema
|
|
143
|
+
state ${schema}.job_state not null default '${JOB_STATES.created}',
|
|
144
144
|
retry_limit integer not null default ${QUEUE_DEFAULTS.retry_limit},
|
|
145
145
|
retry_count integer not null default 0,
|
|
146
146
|
retry_delay integer not null default ${QUEUE_DEFAULTS.retry_delay},
|
|
@@ -182,26 +182,26 @@ const JOB_COLUMNS_ALL = `${JOB_COLUMNS_MIN},
|
|
|
182
182
|
dead_letter as "deadLetter",
|
|
183
183
|
output
|
|
184
184
|
`;
|
|
185
|
-
function createTableJobCommon(schema
|
|
185
|
+
function createTableJobCommon(schema, table) {
|
|
186
186
|
const format = (command) => command.replaceAll(".job", `.${table}`) + ";";
|
|
187
187
|
return `
|
|
188
|
-
CREATE TABLE ${schema
|
|
189
|
-
${format(createPrimaryKeyJob(schema
|
|
190
|
-
${format(createQueueForeignKeyJob(schema
|
|
191
|
-
${format(createQueueForeignKeyJobDeadLetter(schema
|
|
192
|
-
${format(createIndexJobPolicyShort(schema
|
|
193
|
-
${format(createIndexJobPolicySingleton(schema
|
|
194
|
-
${format(createIndexJobPolicyStately(schema
|
|
195
|
-
${format(createIndexJobPolicyExclusive(schema
|
|
196
|
-
${format(createIndexJobThrottle(schema
|
|
197
|
-
${format(createIndexJobFetch(schema
|
|
188
|
+
CREATE TABLE ${schema}.${table} (LIKE ${schema}.job INCLUDING GENERATED INCLUDING DEFAULTS);
|
|
189
|
+
${format(createPrimaryKeyJob(schema))}
|
|
190
|
+
${format(createQueueForeignKeyJob(schema))}
|
|
191
|
+
${format(createQueueForeignKeyJobDeadLetter(schema))}
|
|
192
|
+
${format(createIndexJobPolicyShort(schema))}
|
|
193
|
+
${format(createIndexJobPolicySingleton(schema))}
|
|
194
|
+
${format(createIndexJobPolicyStately(schema))}
|
|
195
|
+
${format(createIndexJobPolicyExclusive(schema))}
|
|
196
|
+
${format(createIndexJobThrottle(schema))}
|
|
197
|
+
${format(createIndexJobFetch(schema))}
|
|
198
198
|
|
|
199
|
-
ALTER TABLE ${schema
|
|
199
|
+
ALTER TABLE ${schema}.job ATTACH PARTITION ${schema}.${table} DEFAULT;
|
|
200
200
|
`;
|
|
201
201
|
}
|
|
202
|
-
function createQueueFunction(schema
|
|
202
|
+
function createQueueFunction(schema) {
|
|
203
203
|
return `
|
|
204
|
-
CREATE FUNCTION ${schema
|
|
204
|
+
CREATE FUNCTION ${schema}.create_queue(queue_name text, options jsonb)
|
|
205
205
|
RETURNS VOID AS
|
|
206
206
|
$$
|
|
207
207
|
DECLARE
|
|
@@ -213,7 +213,7 @@ function createQueueFunction(schema$1) {
|
|
|
213
213
|
BEGIN
|
|
214
214
|
|
|
215
215
|
WITH q as (
|
|
216
|
-
INSERT INTO ${schema
|
|
216
|
+
INSERT INTO ${schema}.queue (
|
|
217
217
|
name,
|
|
218
218
|
policy,
|
|
219
219
|
retry_limit,
|
|
@@ -252,27 +252,27 @@ function createQueueFunction(schema$1) {
|
|
|
252
252
|
RETURN;
|
|
253
253
|
END IF;
|
|
254
254
|
|
|
255
|
-
EXECUTE format('CREATE TABLE ${schema
|
|
255
|
+
EXECUTE format('CREATE TABLE ${schema}.%I (LIKE ${schema}.job INCLUDING DEFAULTS)', tablename);
|
|
256
256
|
|
|
257
|
-
EXECUTE format('${formatPartitionCommand(createPrimaryKeyJob(schema
|
|
258
|
-
EXECUTE format('${formatPartitionCommand(createQueueForeignKeyJob(schema
|
|
259
|
-
EXECUTE format('${formatPartitionCommand(createQueueForeignKeyJobDeadLetter(schema
|
|
257
|
+
EXECUTE format('${formatPartitionCommand(createPrimaryKeyJob(schema))}', tablename);
|
|
258
|
+
EXECUTE format('${formatPartitionCommand(createQueueForeignKeyJob(schema))}', tablename);
|
|
259
|
+
EXECUTE format('${formatPartitionCommand(createQueueForeignKeyJobDeadLetter(schema))}', tablename);
|
|
260
260
|
|
|
261
|
-
EXECUTE format('${formatPartitionCommand(createIndexJobFetch(schema
|
|
262
|
-
EXECUTE format('${formatPartitionCommand(createIndexJobThrottle(schema
|
|
261
|
+
EXECUTE format('${formatPartitionCommand(createIndexJobFetch(schema))}', tablename);
|
|
262
|
+
EXECUTE format('${formatPartitionCommand(createIndexJobThrottle(schema))}', tablename);
|
|
263
263
|
|
|
264
264
|
IF options->>'policy' = 'short' THEN
|
|
265
|
-
EXECUTE format('${formatPartitionCommand(createIndexJobPolicyShort(schema
|
|
265
|
+
EXECUTE format('${formatPartitionCommand(createIndexJobPolicyShort(schema))}', tablename);
|
|
266
266
|
ELSIF options->>'policy' = 'singleton' THEN
|
|
267
|
-
EXECUTE format('${formatPartitionCommand(createIndexJobPolicySingleton(schema
|
|
267
|
+
EXECUTE format('${formatPartitionCommand(createIndexJobPolicySingleton(schema))}', tablename);
|
|
268
268
|
ELSIF options->>'policy' = 'stately' THEN
|
|
269
|
-
EXECUTE format('${formatPartitionCommand(createIndexJobPolicyStately(schema
|
|
269
|
+
EXECUTE format('${formatPartitionCommand(createIndexJobPolicyStately(schema))}', tablename);
|
|
270
270
|
ELSIF options->>'policy' = 'exclusive' THEN
|
|
271
|
-
EXECUTE format('${formatPartitionCommand(createIndexJobPolicyExclusive(schema
|
|
271
|
+
EXECUTE format('${formatPartitionCommand(createIndexJobPolicyExclusive(schema))}', tablename);
|
|
272
272
|
END IF;
|
|
273
273
|
|
|
274
|
-
EXECUTE format('ALTER TABLE ${schema
|
|
275
|
-
EXECUTE format('ALTER TABLE ${schema
|
|
274
|
+
EXECUTE format('ALTER TABLE ${schema}.%I ADD CONSTRAINT cjc CHECK (name=%L)', tablename, queue_name);
|
|
275
|
+
EXECUTE format('ALTER TABLE ${schema}.job ATTACH PARTITION ${schema}.%I FOR VALUES IN (%L)', tablename, queue_name);
|
|
276
276
|
END;
|
|
277
277
|
$$
|
|
278
278
|
LANGUAGE plpgsql;
|
|
@@ -281,9 +281,9 @@ function createQueueFunction(schema$1) {
|
|
|
281
281
|
function formatPartitionCommand(command) {
|
|
282
282
|
return command.replace(".job", ".%1$I").replace("job_i", "%1$s_i").replaceAll("'", "''");
|
|
283
283
|
}
|
|
284
|
-
function deleteQueueFunction(schema
|
|
284
|
+
function deleteQueueFunction(schema) {
|
|
285
285
|
return `
|
|
286
|
-
CREATE FUNCTION ${schema
|
|
286
|
+
CREATE FUNCTION ${schema}.delete_queue(queue_name text)
|
|
287
287
|
RETURNS VOID AS
|
|
288
288
|
$$
|
|
289
289
|
DECLARE
|
|
@@ -291,85 +291,85 @@ function deleteQueueFunction(schema$1) {
|
|
|
291
291
|
v_partition bool;
|
|
292
292
|
BEGIN
|
|
293
293
|
SELECT table_name, partition
|
|
294
|
-
FROM ${schema
|
|
294
|
+
FROM ${schema}.queue
|
|
295
295
|
WHERE name = queue_name
|
|
296
296
|
INTO v_table, v_partition;
|
|
297
297
|
|
|
298
298
|
IF v_partition THEN
|
|
299
|
-
EXECUTE format('DROP TABLE IF EXISTS ${schema
|
|
299
|
+
EXECUTE format('DROP TABLE IF EXISTS ${schema}.%I', v_table);
|
|
300
300
|
ELSE
|
|
301
|
-
EXECUTE format('DELETE FROM ${schema
|
|
301
|
+
EXECUTE format('DELETE FROM ${schema}.%I WHERE name = %L', v_table, queue_name);
|
|
302
302
|
END IF;
|
|
303
303
|
|
|
304
|
-
DELETE FROM ${schema
|
|
304
|
+
DELETE FROM ${schema}.queue WHERE name = queue_name;
|
|
305
305
|
END;
|
|
306
306
|
$$
|
|
307
307
|
LANGUAGE plpgsql;
|
|
308
308
|
`;
|
|
309
309
|
}
|
|
310
|
-
function createQueue(schema
|
|
311
|
-
return locked(schema
|
|
310
|
+
function createQueue(schema, name, options) {
|
|
311
|
+
return locked(schema, `SELECT ${schema}.create_queue('${name}', '${JSON.stringify(options)}'::jsonb)`, "create-queue");
|
|
312
312
|
}
|
|
313
|
-
function deleteQueue(schema
|
|
314
|
-
return locked(schema
|
|
313
|
+
function deleteQueue(schema, name) {
|
|
314
|
+
return locked(schema, `SELECT ${schema}.delete_queue('${name}')`, "delete-queue");
|
|
315
315
|
}
|
|
316
|
-
function createPrimaryKeyJob(schema
|
|
317
|
-
return `ALTER TABLE ${schema
|
|
316
|
+
function createPrimaryKeyJob(schema) {
|
|
317
|
+
return `ALTER TABLE ${schema}.job ADD PRIMARY KEY (name, id)`;
|
|
318
318
|
}
|
|
319
|
-
function createQueueForeignKeyJob(schema
|
|
320
|
-
return `ALTER TABLE ${schema
|
|
319
|
+
function createQueueForeignKeyJob(schema) {
|
|
320
|
+
return `ALTER TABLE ${schema}.job ADD CONSTRAINT q_fkey FOREIGN KEY (name) REFERENCES ${schema}.queue (name) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED`;
|
|
321
321
|
}
|
|
322
|
-
function createQueueForeignKeyJobDeadLetter(schema
|
|
323
|
-
return `ALTER TABLE ${schema
|
|
322
|
+
function createQueueForeignKeyJobDeadLetter(schema) {
|
|
323
|
+
return `ALTER TABLE ${schema}.job ADD CONSTRAINT dlq_fkey FOREIGN KEY (dead_letter) REFERENCES ${schema}.queue (name) ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED`;
|
|
324
324
|
}
|
|
325
|
-
function createIndexJobPolicyShort(schema
|
|
326
|
-
return `CREATE UNIQUE INDEX job_i1 ON ${schema
|
|
325
|
+
function createIndexJobPolicyShort(schema) {
|
|
326
|
+
return `CREATE UNIQUE INDEX job_i1 ON ${schema}.job (name, COALESCE(singleton_key, '')) WHERE state = '${JOB_STATES.created}' AND policy = '${QUEUE_POLICIES.short}'`;
|
|
327
327
|
}
|
|
328
|
-
function createIndexJobPolicySingleton(schema
|
|
329
|
-
return `CREATE UNIQUE INDEX job_i2 ON ${schema
|
|
328
|
+
function createIndexJobPolicySingleton(schema) {
|
|
329
|
+
return `CREATE UNIQUE INDEX job_i2 ON ${schema}.job (name, COALESCE(singleton_key, '')) WHERE state = '${JOB_STATES.active}' AND policy = '${QUEUE_POLICIES.singleton}'`;
|
|
330
330
|
}
|
|
331
|
-
function createIndexJobPolicyStately(schema
|
|
332
|
-
return `CREATE UNIQUE INDEX job_i3 ON ${schema
|
|
331
|
+
function createIndexJobPolicyStately(schema) {
|
|
332
|
+
return `CREATE UNIQUE INDEX job_i3 ON ${schema}.job (name, state, COALESCE(singleton_key, '')) WHERE state <= '${JOB_STATES.active}' AND policy = '${QUEUE_POLICIES.stately}'`;
|
|
333
333
|
}
|
|
334
|
-
function createIndexJobThrottle(schema
|
|
335
|
-
return `CREATE UNIQUE INDEX job_i4 ON ${schema
|
|
334
|
+
function createIndexJobThrottle(schema) {
|
|
335
|
+
return `CREATE UNIQUE INDEX job_i4 ON ${schema}.job (name, singleton_on, COALESCE(singleton_key, '')) WHERE state <> '${JOB_STATES.cancelled}' AND singleton_on IS NOT NULL`;
|
|
336
336
|
}
|
|
337
|
-
function createIndexJobFetch(schema
|
|
338
|
-
return `CREATE INDEX job_i5 ON ${schema
|
|
337
|
+
function createIndexJobFetch(schema) {
|
|
338
|
+
return `CREATE INDEX job_i5 ON ${schema}.job (name, start_after) INCLUDE (priority, created_on, id) WHERE state < '${JOB_STATES.active}'`;
|
|
339
339
|
}
|
|
340
|
-
function createIndexJobPolicyExclusive(schema
|
|
341
|
-
return `CREATE UNIQUE INDEX job_i6 ON ${schema
|
|
340
|
+
function createIndexJobPolicyExclusive(schema) {
|
|
341
|
+
return `CREATE UNIQUE INDEX job_i6 ON ${schema}.job (name, COALESCE(singleton_key, '')) WHERE state <= '${JOB_STATES.active}' AND policy = '${QUEUE_POLICIES.exclusive}'`;
|
|
342
342
|
}
|
|
343
|
-
function trySetQueueMonitorTime(schema
|
|
344
|
-
return trySetQueueTimestamp(schema
|
|
343
|
+
function trySetQueueMonitorTime(schema, queues, seconds) {
|
|
344
|
+
return trySetQueueTimestamp(schema, queues, "monitor_on", seconds);
|
|
345
345
|
}
|
|
346
|
-
function trySetQueueDeletionTime(schema
|
|
347
|
-
return trySetQueueTimestamp(schema
|
|
346
|
+
function trySetQueueDeletionTime(schema, queues, seconds) {
|
|
347
|
+
return trySetQueueTimestamp(schema, queues, "maintain_on", seconds);
|
|
348
348
|
}
|
|
349
|
-
function trySetCronTime(schema
|
|
350
|
-
return trySetTimestamp(schema
|
|
349
|
+
function trySetCronTime(schema, seconds) {
|
|
350
|
+
return trySetTimestamp(schema, "cron_on", seconds);
|
|
351
351
|
}
|
|
352
|
-
function trySetTimestamp(schema
|
|
352
|
+
function trySetTimestamp(schema, column, seconds) {
|
|
353
353
|
return `
|
|
354
|
-
UPDATE ${schema
|
|
354
|
+
UPDATE ${schema}.version
|
|
355
355
|
SET ${column} = now()
|
|
356
356
|
WHERE EXTRACT( EPOCH FROM (now() - COALESCE(${column}, now() - interval '1 week') ) ) > ${seconds}
|
|
357
357
|
RETURNING true
|
|
358
358
|
`;
|
|
359
359
|
}
|
|
360
|
-
function trySetQueueTimestamp(schema
|
|
360
|
+
function trySetQueueTimestamp(schema, queues, column, seconds) {
|
|
361
361
|
return `
|
|
362
|
-
UPDATE ${schema
|
|
362
|
+
UPDATE ${schema}.queue
|
|
363
363
|
SET ${column} = now()
|
|
364
364
|
WHERE name IN(${getQueueInClause(queues)})
|
|
365
365
|
AND EXTRACT( EPOCH FROM (now() - COALESCE(${column}, now() - interval '1 week') ) ) > ${seconds}
|
|
366
366
|
RETURNING name
|
|
367
367
|
`;
|
|
368
368
|
}
|
|
369
|
-
function updateQueue(schema
|
|
369
|
+
function updateQueue(schema, { deadLetter } = {}) {
|
|
370
370
|
return `
|
|
371
371
|
WITH options as (SELECT $2::jsonb as data)
|
|
372
|
-
UPDATE ${schema
|
|
372
|
+
UPDATE ${schema}.queue SET
|
|
373
373
|
retry_limit = COALESCE((o.data->>'retryLimit')::int, retry_limit),
|
|
374
374
|
retry_delay = COALESCE((o.data->>'retryDelay')::int, retry_delay),
|
|
375
375
|
retry_backoff = COALESCE((o.data->>'retryBackoff')::bool, retry_backoff),
|
|
@@ -386,7 +386,7 @@ function updateQueue(schema$1, { deadLetter } = {}) {
|
|
|
386
386
|
WHERE name = $1
|
|
387
387
|
`;
|
|
388
388
|
}
|
|
389
|
-
function getQueues(schema
|
|
389
|
+
function getQueues(schema, names) {
|
|
390
390
|
return `
|
|
391
391
|
SELECT
|
|
392
392
|
q.name,
|
|
@@ -409,14 +409,14 @@ function getQueues(schema$1, names) {
|
|
|
409
409
|
q.table_name as "table",
|
|
410
410
|
q.created_on as "createdOn",
|
|
411
411
|
q.updated_on as "updatedOn"
|
|
412
|
-
FROM ${schema
|
|
412
|
+
FROM ${schema}.queue q
|
|
413
413
|
${names ? `WHERE q.name IN (${names.map((i) => `'${i}'`)})` : ""}
|
|
414
414
|
`;
|
|
415
415
|
}
|
|
416
|
-
function deleteJobsById(schema
|
|
416
|
+
function deleteJobsById(schema, table) {
|
|
417
417
|
return `
|
|
418
418
|
WITH results as (
|
|
419
|
-
DELETE FROM ${schema
|
|
419
|
+
DELETE FROM ${schema}.${table}
|
|
420
420
|
WHERE name = $1
|
|
421
421
|
AND id IN (SELECT UNNEST($2::uuid[]))
|
|
422
422
|
RETURNING 1
|
|
@@ -424,27 +424,27 @@ function deleteJobsById(schema$1, table) {
|
|
|
424
424
|
SELECT COUNT(*) from results
|
|
425
425
|
`;
|
|
426
426
|
}
|
|
427
|
-
function deleteQueuedJobs(schema
|
|
428
|
-
return `DELETE from ${schema
|
|
427
|
+
function deleteQueuedJobs(schema, table) {
|
|
428
|
+
return `DELETE from ${schema}.${table} WHERE name = $1 and state < '${JOB_STATES.active}'`;
|
|
429
429
|
}
|
|
430
|
-
function deleteStoredJobs(schema
|
|
431
|
-
return `DELETE from ${schema
|
|
430
|
+
function deleteStoredJobs(schema, table) {
|
|
431
|
+
return `DELETE from ${schema}.${table} WHERE name = $1 and state > '${JOB_STATES.active}'`;
|
|
432
432
|
}
|
|
433
|
-
function truncateTable(schema
|
|
434
|
-
return `TRUNCATE ${schema
|
|
433
|
+
function truncateTable(schema, table) {
|
|
434
|
+
return `TRUNCATE ${schema}.${table}`;
|
|
435
435
|
}
|
|
436
|
-
function deleteAllJobs(schema
|
|
437
|
-
return `DELETE from ${schema
|
|
436
|
+
function deleteAllJobs(schema, table) {
|
|
437
|
+
return `DELETE from ${schema}.${table} WHERE name = $1`;
|
|
438
438
|
}
|
|
439
|
-
function getSchedules(schema
|
|
440
|
-
return `SELECT * FROM ${schema
|
|
439
|
+
function getSchedules(schema) {
|
|
440
|
+
return `SELECT * FROM ${schema}.schedule`;
|
|
441
441
|
}
|
|
442
|
-
function getSchedulesByQueue(schema
|
|
443
|
-
return `SELECT * FROM ${schema
|
|
442
|
+
function getSchedulesByQueue(schema) {
|
|
443
|
+
return `SELECT * FROM ${schema}.schedule WHERE name = $1 AND COALESCE(key, '') = $2`;
|
|
444
444
|
}
|
|
445
|
-
function schedule(schema
|
|
445
|
+
function schedule(schema) {
|
|
446
446
|
return `
|
|
447
|
-
INSERT INTO ${schema
|
|
447
|
+
INSERT INTO ${schema}.schedule (name, key, cron, timezone, data, options)
|
|
448
448
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
449
449
|
ON CONFLICT (name, key) DO UPDATE SET
|
|
450
450
|
cron = EXCLUDED.cron,
|
|
@@ -454,16 +454,16 @@ function schedule(schema$1) {
|
|
|
454
454
|
updated_on = now()
|
|
455
455
|
`;
|
|
456
456
|
}
|
|
457
|
-
function unschedule(schema
|
|
457
|
+
function unschedule(schema) {
|
|
458
458
|
return `
|
|
459
|
-
DELETE FROM ${schema
|
|
459
|
+
DELETE FROM ${schema}.schedule
|
|
460
460
|
WHERE name = $1
|
|
461
461
|
AND COALESCE(key, '') = $2
|
|
462
462
|
`;
|
|
463
463
|
}
|
|
464
|
-
function subscribe(schema
|
|
464
|
+
function subscribe(schema) {
|
|
465
465
|
return `
|
|
466
|
-
INSERT INTO ${schema
|
|
466
|
+
INSERT INTO ${schema}.subscription (event, name)
|
|
467
467
|
VALUES ($1, $2)
|
|
468
468
|
ON CONFLICT (event, name) DO UPDATE SET
|
|
469
469
|
event = EXCLUDED.event,
|
|
@@ -471,40 +471,40 @@ function subscribe(schema$1) {
|
|
|
471
471
|
updated_on = now()
|
|
472
472
|
`;
|
|
473
473
|
}
|
|
474
|
-
function unsubscribe(schema
|
|
474
|
+
function unsubscribe(schema) {
|
|
475
475
|
return `
|
|
476
|
-
DELETE FROM ${schema
|
|
476
|
+
DELETE FROM ${schema}.subscription
|
|
477
477
|
WHERE event = $1 and name = $2
|
|
478
478
|
`;
|
|
479
479
|
}
|
|
480
|
-
function getQueuesForEvent(schema
|
|
480
|
+
function getQueuesForEvent(schema) {
|
|
481
481
|
return `
|
|
482
|
-
SELECT name FROM ${schema
|
|
482
|
+
SELECT name FROM ${schema}.subscription
|
|
483
483
|
WHERE event = $1
|
|
484
484
|
`;
|
|
485
485
|
}
|
|
486
486
|
function getTime() {
|
|
487
487
|
return "SELECT round(date_part('epoch', now()) * 1000) as time";
|
|
488
488
|
}
|
|
489
|
-
function getVersion(schema
|
|
490
|
-
return `SELECT version from ${schema
|
|
489
|
+
function getVersion(schema) {
|
|
490
|
+
return `SELECT version from ${schema}.version`;
|
|
491
491
|
}
|
|
492
|
-
function setVersion(schema
|
|
493
|
-
return `UPDATE ${schema
|
|
492
|
+
function setVersion(schema, version) {
|
|
493
|
+
return `UPDATE ${schema}.version SET version = '${version}'`;
|
|
494
494
|
}
|
|
495
|
-
function versionTableExists(schema
|
|
496
|
-
return `SELECT to_regclass('${schema
|
|
495
|
+
function versionTableExists(schema) {
|
|
496
|
+
return `SELECT to_regclass('${schema}.version') as name`;
|
|
497
497
|
}
|
|
498
|
-
function insertVersion(schema
|
|
499
|
-
return `INSERT INTO ${schema
|
|
498
|
+
function insertVersion(schema, version) {
|
|
499
|
+
return `INSERT INTO ${schema}.version(version) VALUES ('${version}')`;
|
|
500
500
|
}
|
|
501
|
-
function fetchNextJob({ schema
|
|
501
|
+
function fetchNextJob({ schema, table, name, policy, limit, includeMetadata, priority = true, ignoreStartAfter = false, ignoreSingletons = null }) {
|
|
502
502
|
const singletonFetch = limit > 1 && (policy === QUEUE_POLICIES.singleton || policy === QUEUE_POLICIES.stately);
|
|
503
503
|
const cte = singletonFetch ? "grouped" : "next";
|
|
504
504
|
return `
|
|
505
505
|
WITH next as (
|
|
506
506
|
SELECT id ${singletonFetch ? ", singleton_key" : ""}
|
|
507
|
-
FROM ${schema
|
|
507
|
+
FROM ${schema}.${table}
|
|
508
508
|
WHERE name = '${name}'
|
|
509
509
|
AND state < '${JOB_STATES.active}'
|
|
510
510
|
${ignoreStartAfter ? "" : "AND start_after < now()"}
|
|
@@ -514,7 +514,7 @@ function fetchNextJob({ schema: schema$1, table, name, policy, limit, includeMet
|
|
|
514
514
|
FOR UPDATE SKIP LOCKED
|
|
515
515
|
)
|
|
516
516
|
${singletonFetch ? ", grouped as ( SELECT id, row_number() OVER (PARTITION BY singleton_key) FROM next)" : ""}
|
|
517
|
-
UPDATE ${schema
|
|
517
|
+
UPDATE ${schema}.${table} j SET
|
|
518
518
|
state = '${JOB_STATES.active}',
|
|
519
519
|
started_on = now(),
|
|
520
520
|
retry_count = CASE WHEN started_on IS NOT NULL THEN retry_count + 1 ELSE retry_count END
|
|
@@ -524,10 +524,10 @@ function fetchNextJob({ schema: schema$1, table, name, policy, limit, includeMet
|
|
|
524
524
|
RETURNING j.${includeMetadata ? JOB_COLUMNS_ALL : JOB_COLUMNS_MIN}
|
|
525
525
|
`;
|
|
526
526
|
}
|
|
527
|
-
function completeJobs(schema
|
|
527
|
+
function completeJobs(schema, table) {
|
|
528
528
|
return `
|
|
529
529
|
WITH results AS (
|
|
530
|
-
UPDATE ${schema
|
|
530
|
+
UPDATE ${schema}.${table}
|
|
531
531
|
SET completed_on = now(),
|
|
532
532
|
state = '${JOB_STATES.completed}',
|
|
533
533
|
output = $3::jsonb
|
|
@@ -539,10 +539,10 @@ function completeJobs(schema$1, table) {
|
|
|
539
539
|
SELECT COUNT(*) FROM results
|
|
540
540
|
`;
|
|
541
541
|
}
|
|
542
|
-
function cancelJobs(schema
|
|
542
|
+
function cancelJobs(schema, table) {
|
|
543
543
|
return `
|
|
544
544
|
WITH results as (
|
|
545
|
-
UPDATE ${schema
|
|
545
|
+
UPDATE ${schema}.${table}
|
|
546
546
|
SET completed_on = now(),
|
|
547
547
|
state = '${JOB_STATES.cancelled}'
|
|
548
548
|
WHERE name = $1
|
|
@@ -553,10 +553,10 @@ function cancelJobs(schema$1, table) {
|
|
|
553
553
|
SELECT COUNT(*) from results
|
|
554
554
|
`;
|
|
555
555
|
}
|
|
556
|
-
function resumeJobs(schema
|
|
556
|
+
function resumeJobs(schema, table) {
|
|
557
557
|
return `
|
|
558
558
|
WITH results as (
|
|
559
|
-
UPDATE ${schema
|
|
559
|
+
UPDATE ${schema}.${table}
|
|
560
560
|
SET completed_on = NULL,
|
|
561
561
|
state = '${JOB_STATES.created}'
|
|
562
562
|
WHERE name = $1
|
|
@@ -567,9 +567,9 @@ function resumeJobs(schema$1, table) {
|
|
|
567
567
|
SELECT COUNT(*) from results
|
|
568
568
|
`;
|
|
569
569
|
}
|
|
570
|
-
function insertJobs(schema
|
|
570
|
+
function insertJobs(schema, { table, name, returnId = true }) {
|
|
571
571
|
return `
|
|
572
|
-
INSERT INTO ${schema
|
|
572
|
+
INSERT INTO ${schema}.${table} (
|
|
573
573
|
id,
|
|
574
574
|
name,
|
|
575
575
|
data,
|
|
@@ -631,28 +631,28 @@ function insertJobs(schema$1, { table, name, returnId = true }) {
|
|
|
631
631
|
"retentionSeconds" integer
|
|
632
632
|
)
|
|
633
633
|
) j
|
|
634
|
-
JOIN ${schema
|
|
634
|
+
JOIN ${schema}.queue q ON q.name = '${name}'
|
|
635
635
|
ON CONFLICT DO NOTHING
|
|
636
636
|
${returnId ? "RETURNING id" : ""}
|
|
637
637
|
`;
|
|
638
638
|
}
|
|
639
|
-
function failJobsById(schema
|
|
640
|
-
return failJobs(schema
|
|
639
|
+
function failJobsById(schema, table) {
|
|
640
|
+
return failJobs(schema, table, `name = $1 AND id IN (SELECT UNNEST($2::uuid[])) AND state < '${JOB_STATES.completed}'`, "$3::jsonb");
|
|
641
641
|
}
|
|
642
|
-
function failJobsByTimeout(schema
|
|
643
|
-
return locked(schema
|
|
642
|
+
function failJobsByTimeout(schema, table, queues) {
|
|
643
|
+
return locked(schema, failJobs(schema, table, `state = '${JOB_STATES.active}'
|
|
644
644
|
AND (started_on + expire_seconds * interval '1s') < now()
|
|
645
645
|
AND name IN (${getQueueInClause(queues)})`, "'{ \"value\": { \"message\": \"job timed out\" } }'::jsonb"), table + "failJobsByTimeout");
|
|
646
646
|
}
|
|
647
|
-
function failJobs(schema
|
|
647
|
+
function failJobs(schema, table, where, output) {
|
|
648
648
|
return `
|
|
649
649
|
WITH deleted_jobs AS (
|
|
650
|
-
DELETE FROM ${schema
|
|
650
|
+
DELETE FROM ${schema}.${table}
|
|
651
651
|
WHERE ${where}
|
|
652
652
|
RETURNING *
|
|
653
653
|
),
|
|
654
654
|
retried_jobs AS (
|
|
655
|
-
INSERT INTO ${schema
|
|
655
|
+
INSERT INTO ${schema}.${table} (
|
|
656
656
|
id,
|
|
657
657
|
name,
|
|
658
658
|
priority,
|
|
@@ -682,8 +682,8 @@ function failJobs(schema$1, table, where, output) {
|
|
|
682
682
|
priority,
|
|
683
683
|
data,
|
|
684
684
|
CASE
|
|
685
|
-
WHEN retry_count < retry_limit THEN '${JOB_STATES.retry}'::${schema
|
|
686
|
-
ELSE '${JOB_STATES.failed}'::${schema
|
|
685
|
+
WHEN retry_count < retry_limit THEN '${JOB_STATES.retry}'::${schema}.job_state
|
|
686
|
+
ELSE '${JOB_STATES.failed}'::${schema}.job_state
|
|
687
687
|
END as state,
|
|
688
688
|
retry_limit,
|
|
689
689
|
retry_count,
|
|
@@ -716,7 +716,7 @@ function failJobs(schema$1, table, where, output) {
|
|
|
716
716
|
RETURNING *
|
|
717
717
|
),
|
|
718
718
|
failed_jobs as (
|
|
719
|
-
INSERT INTO ${schema
|
|
719
|
+
INSERT INTO ${schema}.${table} (
|
|
720
720
|
id,
|
|
721
721
|
name,
|
|
722
722
|
priority,
|
|
@@ -745,7 +745,7 @@ function failJobs(schema$1, table, where, output) {
|
|
|
745
745
|
name,
|
|
746
746
|
priority,
|
|
747
747
|
data,
|
|
748
|
-
'${JOB_STATES.failed}'::${schema
|
|
748
|
+
'${JOB_STATES.failed}'::${schema}.job_state as state,
|
|
749
749
|
retry_limit,
|
|
750
750
|
retry_count,
|
|
751
751
|
retry_delay,
|
|
@@ -773,7 +773,7 @@ function failJobs(schema$1, table, where, output) {
|
|
|
773
773
|
SELECT * FROM failed_jobs
|
|
774
774
|
),
|
|
775
775
|
dlq_jobs as (
|
|
776
|
-
INSERT INTO ${schema
|
|
776
|
+
INSERT INTO ${schema}.job (name, data, output, retry_limit, retry_backoff, retry_delay, keep_until, deletion_seconds)
|
|
777
777
|
SELECT
|
|
778
778
|
r.dead_letter,
|
|
779
779
|
data,
|
|
@@ -784,15 +784,15 @@ function failJobs(schema$1, table, where, output) {
|
|
|
784
784
|
now() + q.retention_seconds * interval '1s',
|
|
785
785
|
q.deletion_seconds
|
|
786
786
|
FROM results r
|
|
787
|
-
JOIN ${schema
|
|
787
|
+
JOIN ${schema}.queue q ON q.name = r.dead_letter
|
|
788
788
|
WHERE state = '${JOB_STATES.failed}'
|
|
789
789
|
)
|
|
790
790
|
SELECT COUNT(*) FROM results
|
|
791
791
|
`;
|
|
792
792
|
}
|
|
793
|
-
function deletion(schema
|
|
794
|
-
return locked(schema
|
|
795
|
-
DELETE FROM ${schema
|
|
793
|
+
function deletion(schema, table, queues) {
|
|
794
|
+
return locked(schema, `
|
|
795
|
+
DELETE FROM ${schema}.${table}
|
|
796
796
|
WHERE name IN (${getQueueInClause(queues)})
|
|
797
797
|
AND
|
|
798
798
|
(
|
|
@@ -802,10 +802,10 @@ function deletion(schema$1, table, queues) {
|
|
|
802
802
|
)
|
|
803
803
|
`, table + "deletion");
|
|
804
804
|
}
|
|
805
|
-
function retryJobs(schema
|
|
805
|
+
function retryJobs(schema, table) {
|
|
806
806
|
return `
|
|
807
807
|
WITH results as (
|
|
808
|
-
UPDATE ${schema
|
|
808
|
+
UPDATE ${schema}.job
|
|
809
809
|
SET state = '${JOB_STATES.retry}',
|
|
810
810
|
retry_limit = retry_limit + 1
|
|
811
811
|
WHERE name = $1
|
|
@@ -816,7 +816,7 @@ function retryJobs(schema$1, table) {
|
|
|
816
816
|
SELECT COUNT(*) from results
|
|
817
817
|
`;
|
|
818
818
|
}
|
|
819
|
-
function getQueueStats(schema
|
|
819
|
+
function getQueueStats(schema, table, queues) {
|
|
820
820
|
return `
|
|
821
821
|
SELECT
|
|
822
822
|
name,
|
|
@@ -825,15 +825,15 @@ function getQueueStats(schema$1, table, queues) {
|
|
|
825
825
|
(count(*) FILTER (WHERE state = '${JOB_STATES.active}'))::int as "activeCount",
|
|
826
826
|
count(*)::int as "totalCount",
|
|
827
827
|
array_agg(singleton_key) FILTER (WHERE policy IN ('${QUEUE_POLICIES.singleton}','${QUEUE_POLICIES.stately}') AND state = '${JOB_STATES.active}') as "singletonsActive"
|
|
828
|
-
FROM ${schema
|
|
828
|
+
FROM ${schema}.${table}
|
|
829
829
|
WHERE name IN (${getQueueInClause(queues)})
|
|
830
830
|
GROUP BY 1
|
|
831
831
|
`;
|
|
832
832
|
}
|
|
833
|
-
function cacheQueueStats(schema
|
|
834
|
-
return locked(schema
|
|
835
|
-
WITH stats AS (${getQueueStats(schema
|
|
836
|
-
UPDATE ${schema
|
|
833
|
+
function cacheQueueStats(schema, table, queues) {
|
|
834
|
+
return locked(schema, `
|
|
835
|
+
WITH stats AS (${getQueueStats(schema, table, queues)})
|
|
836
|
+
UPDATE ${schema}.queue SET
|
|
837
837
|
deferred_count = "deferredCount",
|
|
838
838
|
queued_count = "queuedCount",
|
|
839
839
|
active_count = "activeCount",
|
|
@@ -847,27 +847,27 @@ function cacheQueueStats(schema$1, table, queues) {
|
|
|
847
847
|
warning_queued as "warningQueueSize"
|
|
848
848
|
`, "queue-stats");
|
|
849
849
|
}
|
|
850
|
-
function locked(schema
|
|
850
|
+
function locked(schema, query, key) {
|
|
851
851
|
if (Array.isArray(query)) query = query.join(";\n");
|
|
852
852
|
return `
|
|
853
853
|
BEGIN;
|
|
854
854
|
SET LOCAL lock_timeout = 30000;
|
|
855
855
|
SET LOCAL idle_in_transaction_session_timeout = 30000;
|
|
856
|
-
${advisoryLock(schema
|
|
856
|
+
${advisoryLock(schema, key)};
|
|
857
857
|
${query};
|
|
858
858
|
COMMIT;
|
|
859
859
|
`;
|
|
860
860
|
}
|
|
861
|
-
function advisoryLock(schema
|
|
861
|
+
function advisoryLock(schema, key) {
|
|
862
862
|
return `SELECT pg_advisory_xact_lock(
|
|
863
|
-
('x' || encode(sha224((current_database() || '.pgboss.${schema
|
|
863
|
+
('x' || encode(sha224((current_database() || '.pgboss.${schema}${key || ""}')::bytea), 'hex'))::bit(64)::bigint
|
|
864
864
|
)`;
|
|
865
865
|
}
|
|
866
|
-
function assertMigration(schema
|
|
867
|
-
return `SELECT version::int/(version::int-${version}) from ${schema
|
|
866
|
+
function assertMigration(schema, version) {
|
|
867
|
+
return `SELECT version::int/(version::int-${version}) from ${schema}.version`;
|
|
868
868
|
}
|
|
869
|
-
function getJobById(schema
|
|
870
|
-
return `SELECT ${JOB_COLUMNS_ALL} FROM ${schema
|
|
869
|
+
function getJobById(schema, table) {
|
|
870
|
+
return `SELECT ${JOB_COLUMNS_ALL} FROM ${schema}.${table} WHERE name = $1 AND id = $2`;
|
|
871
871
|
}
|
|
872
872
|
function getQueueInClause(queues) {
|
|
873
873
|
return queues.map((i) => `'${i}'`).join(",");
|
|
@@ -1033,25 +1033,25 @@ function applyScheduleConfig(config) {
|
|
|
1033
1033
|
|
|
1034
1034
|
//#endregion
|
|
1035
1035
|
//#region src/migrationStore.ts
|
|
1036
|
-
function flatten(schema
|
|
1037
|
-
commands.unshift(assertMigration(schema
|
|
1038
|
-
commands.push(setVersion(schema
|
|
1039
|
-
return locked(schema
|
|
1036
|
+
function flatten(schema, commands, version) {
|
|
1037
|
+
commands.unshift(assertMigration(schema, version));
|
|
1038
|
+
commands.push(setVersion(schema, version));
|
|
1039
|
+
return locked(schema, commands);
|
|
1040
1040
|
}
|
|
1041
|
-
function rollback(schema
|
|
1042
|
-
migrations = migrations || getAll(schema
|
|
1041
|
+
function rollback(schema, version, migrations) {
|
|
1042
|
+
migrations = migrations || getAll(schema);
|
|
1043
1043
|
const result = migrations.find((i) => i.version === version);
|
|
1044
1044
|
assert(result, `Version ${version} not found.`);
|
|
1045
|
-
return flatten(schema
|
|
1045
|
+
return flatten(schema, result.uninstall || [], result.previous);
|
|
1046
1046
|
}
|
|
1047
|
-
function next(schema
|
|
1048
|
-
migrations = migrations || getAll(schema
|
|
1047
|
+
function next(schema, version, migrations) {
|
|
1048
|
+
migrations = migrations || getAll(schema);
|
|
1049
1049
|
const result = migrations.find((i) => i.previous === version);
|
|
1050
1050
|
assert(result, `Version ${version} not found.`);
|
|
1051
|
-
return flatten(schema
|
|
1051
|
+
return flatten(schema, result.install, result.version);
|
|
1052
1052
|
}
|
|
1053
|
-
function migrate(schema
|
|
1054
|
-
migrations = migrations || getAll(schema
|
|
1053
|
+
function migrate(schema, version, migrations) {
|
|
1054
|
+
migrations = migrations || getAll(schema);
|
|
1055
1055
|
const result = migrations.filter((i) => i.previous >= version).sort((a, b) => a.version - b.version).reduce((acc, i) => {
|
|
1056
1056
|
acc.install = acc.install.concat(i.install);
|
|
1057
1057
|
acc.version = i.version;
|
|
@@ -1061,15 +1061,15 @@ function migrate(schema$1, version, migrations) {
|
|
|
1061
1061
|
version
|
|
1062
1062
|
});
|
|
1063
1063
|
assert(result.install.length > 0, `Version ${version} not found.`);
|
|
1064
|
-
return flatten(schema
|
|
1064
|
+
return flatten(schema, result.install, result.version);
|
|
1065
1065
|
}
|
|
1066
|
-
function getAll(schema
|
|
1066
|
+
function getAll(schema) {
|
|
1067
1067
|
return [{
|
|
1068
1068
|
release: "11.1.0",
|
|
1069
1069
|
version: 26,
|
|
1070
1070
|
previous: 25,
|
|
1071
1071
|
install: [`
|
|
1072
|
-
CREATE OR REPLACE FUNCTION ${schema
|
|
1072
|
+
CREATE OR REPLACE FUNCTION ${schema}.create_queue(queue_name text, options jsonb)
|
|
1073
1073
|
RETURNS VOID AS
|
|
1074
1074
|
$$
|
|
1075
1075
|
DECLARE
|
|
@@ -1081,7 +1081,7 @@ function getAll(schema$1) {
|
|
|
1081
1081
|
BEGIN
|
|
1082
1082
|
|
|
1083
1083
|
WITH q as (
|
|
1084
|
-
INSERT INTO ${schema
|
|
1084
|
+
INSERT INTO ${schema}.queue (
|
|
1085
1085
|
name,
|
|
1086
1086
|
policy,
|
|
1087
1087
|
retry_limit,
|
|
@@ -1120,51 +1120,51 @@ function getAll(schema$1) {
|
|
|
1120
1120
|
RETURN;
|
|
1121
1121
|
END IF;
|
|
1122
1122
|
|
|
1123
|
-
EXECUTE format('CREATE TABLE ${schema
|
|
1123
|
+
EXECUTE format('CREATE TABLE ${schema}.%I (LIKE ${schema}.job INCLUDING DEFAULTS)', tablename);
|
|
1124
1124
|
|
|
1125
|
-
EXECUTE format('ALTER TABLE ${schema
|
|
1126
|
-
EXECUTE format('ALTER TABLE ${schema
|
|
1127
|
-
EXECUTE format('ALTER TABLE ${schema
|
|
1125
|
+
EXECUTE format('ALTER TABLE ${schema}.%1$I ADD PRIMARY KEY (name, id)', tablename);
|
|
1126
|
+
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);
|
|
1127
|
+
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);
|
|
1128
1128
|
|
|
1129
|
-
EXECUTE format('CREATE INDEX %1$s_i5 ON ${schema
|
|
1130
|
-
EXECUTE format('CREATE UNIQUE INDEX %1$s_i4 ON ${schema
|
|
1129
|
+
EXECUTE format('CREATE INDEX %1$s_i5 ON ${schema}.%1$I (name, start_after) INCLUDE (priority, created_on, id) WHERE state < ''active''', tablename);
|
|
1130
|
+
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);
|
|
1131
1131
|
|
|
1132
1132
|
IF options->>'policy' = 'short' THEN
|
|
1133
|
-
EXECUTE format('CREATE UNIQUE INDEX %1$s_i1 ON ${schema
|
|
1133
|
+
EXECUTE format('CREATE UNIQUE INDEX %1$s_i1 ON ${schema}.%1$I (name, COALESCE(singleton_key, '''')) WHERE state = ''created'' AND policy = ''short''', tablename);
|
|
1134
1134
|
ELSIF options->>'policy' = 'singleton' THEN
|
|
1135
|
-
EXECUTE format('CREATE UNIQUE INDEX %1$s_i2 ON ${schema
|
|
1135
|
+
EXECUTE format('CREATE UNIQUE INDEX %1$s_i2 ON ${schema}.%1$I (name, COALESCE(singleton_key, '''')) WHERE state = ''active'' AND policy = ''singleton''', tablename);
|
|
1136
1136
|
ELSIF options->>'policy' = 'stately' THEN
|
|
1137
|
-
EXECUTE format('CREATE UNIQUE INDEX %1$s_i3 ON ${schema
|
|
1137
|
+
EXECUTE format('CREATE UNIQUE INDEX %1$s_i3 ON ${schema}.%1$I (name, state, COALESCE(singleton_key, '''')) WHERE state <= ''active'' AND policy = ''stately''', tablename);
|
|
1138
1138
|
ELSIF options->>'policy' = 'exclusive' THEN
|
|
1139
|
-
EXECUTE format('CREATE UNIQUE INDEX %1$s_i6 ON ${schema
|
|
1139
|
+
EXECUTE format('CREATE UNIQUE INDEX %1$s_i6 ON ${schema}.%1$I (name, COALESCE(singleton_key, '''')) WHERE state <= ''active'' AND policy = ''exclusive''', tablename);
|
|
1140
1140
|
END IF;
|
|
1141
1141
|
|
|
1142
|
-
EXECUTE format('ALTER TABLE ${schema
|
|
1143
|
-
EXECUTE format('ALTER TABLE ${schema
|
|
1142
|
+
EXECUTE format('ALTER TABLE ${schema}.%I ADD CONSTRAINT cjc CHECK (name=%L)', tablename, queue_name);
|
|
1143
|
+
EXECUTE format('ALTER TABLE ${schema}.job ATTACH PARTITION ${schema}.%I FOR VALUES IN (%L)', tablename, queue_name);
|
|
1144
1144
|
END;
|
|
1145
1145
|
$$
|
|
1146
1146
|
LANGUAGE plpgsql;
|
|
1147
|
-
`, `CREATE UNIQUE INDEX job_i6 ON ${schema
|
|
1148
|
-
uninstall: [`DROP INDEX ${schema
|
|
1147
|
+
`, `CREATE UNIQUE INDEX job_i6 ON ${schema}.job_common (name, COALESCE(singleton_key, '')) WHERE state <= 'active' AND policy = 'exclusive'`],
|
|
1148
|
+
uninstall: [`DROP INDEX ${schema}.job_i6`]
|
|
1149
1149
|
}];
|
|
1150
1150
|
}
|
|
1151
1151
|
|
|
1152
1152
|
//#endregion
|
|
1153
|
-
//#region
|
|
1154
|
-
var
|
|
1153
|
+
//#region package.json
|
|
1154
|
+
var pgboss = { "schema": 26 };
|
|
1155
1155
|
|
|
1156
1156
|
//#endregion
|
|
1157
1157
|
//#region src/contractor.ts
|
|
1158
|
-
const schemaVersion = schema;
|
|
1158
|
+
const schemaVersion = pgboss.schema;
|
|
1159
1159
|
var Contractor = class {
|
|
1160
|
-
static constructionPlans(schema
|
|
1161
|
-
return create(schema
|
|
1160
|
+
static constructionPlans(schema = DEFAULT_SCHEMA) {
|
|
1161
|
+
return create(schema, schemaVersion);
|
|
1162
1162
|
}
|
|
1163
|
-
static migrationPlans(schema
|
|
1164
|
-
return migrate(schema
|
|
1163
|
+
static migrationPlans(schema = DEFAULT_SCHEMA, version = schemaVersion - 1) {
|
|
1164
|
+
return migrate(schema, version);
|
|
1165
1165
|
}
|
|
1166
|
-
static rollbackPlans(schema
|
|
1167
|
-
return rollback(schema
|
|
1166
|
+
static rollbackPlans(schema = DEFAULT_SCHEMA, version = schemaVersion) {
|
|
1167
|
+
return rollback(schema, version);
|
|
1168
1168
|
}
|
|
1169
1169
|
config;
|
|
1170
1170
|
db;
|
|
@@ -2169,14 +2169,14 @@ var PgBoss = class extends EventEmitter {
|
|
|
2169
2169
|
#promoteEvents(emitter) {
|
|
2170
2170
|
for (const event of Object.values(emitter?.events)) emitter.on(event, (arg) => this.emit(event, arg));
|
|
2171
2171
|
}
|
|
2172
|
-
static getConstructionPlans(schema
|
|
2173
|
-
return contractor_default.constructionPlans(schema
|
|
2172
|
+
static getConstructionPlans(schema) {
|
|
2173
|
+
return contractor_default.constructionPlans(schema);
|
|
2174
2174
|
}
|
|
2175
|
-
static getMigrationPlans(schema
|
|
2176
|
-
return contractor_default.migrationPlans(schema
|
|
2175
|
+
static getMigrationPlans(schema, version) {
|
|
2176
|
+
return contractor_default.migrationPlans(schema, version);
|
|
2177
2177
|
}
|
|
2178
|
-
static getRollbackPlans(schema
|
|
2179
|
-
return contractor_default.rollbackPlans(schema
|
|
2178
|
+
static getRollbackPlans(schema, version) {
|
|
2179
|
+
return contractor_default.rollbackPlans(schema, version);
|
|
2180
2180
|
}
|
|
2181
2181
|
static states = JOB_STATES;
|
|
2182
2182
|
static policies = QUEUE_POLICIES;
|
|
@@ -2341,9 +2341,10 @@ var PgBoss = class extends EventEmitter {
|
|
|
2341
2341
|
return new db_default(this.#config);
|
|
2342
2342
|
}
|
|
2343
2343
|
};
|
|
2344
|
-
const { states, policies, getConstructionPlans, getMigrationPlans, getRollbackPlans } = PgBoss;
|
|
2345
2344
|
var src_default = PgBoss;
|
|
2345
|
+
const states = PgBoss.states;
|
|
2346
|
+
const policies = PgBoss.policies;
|
|
2346
2347
|
|
|
2347
2348
|
//#endregion
|
|
2348
|
-
export {
|
|
2349
|
+
export { src_default as default, policies, states };
|
|
2349
2350
|
//# sourceMappingURL=index.mjs.map
|