pg-boss 10.0.0-beta11 → 10.0.0-beta13
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 +1 -1
- package/src/attorney.js +1 -0
- package/src/manager.js +39 -25
- package/src/plans.js +114 -103
- package/types.d.ts +5 -4
package/package.json
CHANGED
package/src/attorney.js
CHANGED
|
@@ -186,6 +186,7 @@ function assertPostgresObjectName (name) {
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
function assertQueueName (name) {
|
|
189
|
+
assert(name, 'Name is required')
|
|
189
190
|
assert(typeof name === 'string', 'Name must be a string')
|
|
190
191
|
assert(/[\w-]/.test(name), 'Name can only contain alphanumeric characters, underscores, or hyphens')
|
|
191
192
|
}
|
package/src/manager.js
CHANGED
|
@@ -58,6 +58,7 @@ class Manager extends EventEmitter {
|
|
|
58
58
|
this.getArchivedJobByIdCommand = plans.getArchivedJobById(config.schema)
|
|
59
59
|
this.subscribeCommand = plans.subscribe(config.schema)
|
|
60
60
|
this.unsubscribeCommand = plans.unsubscribe(config.schema)
|
|
61
|
+
this.getQueuesCommand = plans.getQueues(config.schema)
|
|
61
62
|
this.getQueuesForEventCommand = plans.getQueuesForEvent(config.schema)
|
|
62
63
|
|
|
63
64
|
// exported api to index
|
|
@@ -80,10 +81,11 @@ class Manager extends EventEmitter {
|
|
|
80
81
|
this.sendAfter,
|
|
81
82
|
this.createQueue,
|
|
82
83
|
this.updateQueue,
|
|
83
|
-
this.getQueue,
|
|
84
84
|
this.deleteQueue,
|
|
85
85
|
this.purgeQueue,
|
|
86
86
|
this.getQueueSize,
|
|
87
|
+
this.getQueue,
|
|
88
|
+
this.getQueues,
|
|
87
89
|
this.clearStorage,
|
|
88
90
|
this.getJobById
|
|
89
91
|
]
|
|
@@ -509,7 +511,7 @@ class Manager extends EventEmitter {
|
|
|
509
511
|
}
|
|
510
512
|
|
|
511
513
|
async complete (name, id, data, options = {}) {
|
|
512
|
-
|
|
514
|
+
Attorney.assertQueueName(name)
|
|
513
515
|
const db = options.db || this.db
|
|
514
516
|
const ids = this.mapCompletionIdArg(id, 'complete')
|
|
515
517
|
const result = await db.executeSql(this.completeJobsCommand, [name, ids, this.mapCompletionDataArg(data)])
|
|
@@ -517,7 +519,7 @@ class Manager extends EventEmitter {
|
|
|
517
519
|
}
|
|
518
520
|
|
|
519
521
|
async fail (name, id, data, options = {}) {
|
|
520
|
-
|
|
522
|
+
Attorney.assertQueueName(name)
|
|
521
523
|
const db = options.db || this.db
|
|
522
524
|
const ids = this.mapCompletionIdArg(id, 'fail')
|
|
523
525
|
const result = await db.executeSql(this.failJobsByIdCommand, [name, ids, this.mapCompletionDataArg(data)])
|
|
@@ -525,7 +527,7 @@ class Manager extends EventEmitter {
|
|
|
525
527
|
}
|
|
526
528
|
|
|
527
529
|
async cancel (name, id, options = {}) {
|
|
528
|
-
|
|
530
|
+
Attorney.assertQueueName(name)
|
|
529
531
|
const db = options.db || this.db
|
|
530
532
|
const ids = this.mapCompletionIdArg(id, 'cancel')
|
|
531
533
|
const result = await db.executeSql(this.cancelJobsCommand, [name, ids])
|
|
@@ -533,7 +535,7 @@ class Manager extends EventEmitter {
|
|
|
533
535
|
}
|
|
534
536
|
|
|
535
537
|
async resume (name, id, options = {}) {
|
|
536
|
-
|
|
538
|
+
Attorney.assertQueueName(name)
|
|
537
539
|
const db = options.db || this.db
|
|
538
540
|
const ids = this.mapCompletionIdArg(id, 'resume')
|
|
539
541
|
const result = await db.executeSql(this.resumeJobsCommand, [name, ids])
|
|
@@ -541,7 +543,7 @@ class Manager extends EventEmitter {
|
|
|
541
543
|
}
|
|
542
544
|
|
|
543
545
|
async createQueue (name, options = {}) {
|
|
544
|
-
|
|
546
|
+
name = name || options.name
|
|
545
547
|
|
|
546
548
|
Attorney.assertQueueName(name)
|
|
547
549
|
|
|
@@ -558,11 +560,15 @@ class Manager extends EventEmitter {
|
|
|
558
560
|
deadLetter
|
|
559
561
|
} = Attorney.checkQueueArgs(name, options)
|
|
560
562
|
|
|
563
|
+
if (deadLetter) {
|
|
564
|
+
Attorney.assertQueueName(deadLetter)
|
|
565
|
+
}
|
|
566
|
+
|
|
561
567
|
const paritionSql = plans.createPartition(this.config.schema, name)
|
|
562
568
|
|
|
563
569
|
await this.db.executeSql(paritionSql)
|
|
564
570
|
|
|
565
|
-
const sql = plans.
|
|
571
|
+
const sql = plans.insertQueue(this.config.schema)
|
|
566
572
|
|
|
567
573
|
const params = [
|
|
568
574
|
name,
|
|
@@ -578,8 +584,17 @@ class Manager extends EventEmitter {
|
|
|
578
584
|
await this.db.executeSql(sql, params)
|
|
579
585
|
}
|
|
580
586
|
|
|
587
|
+
async getQueues () {
|
|
588
|
+
const { rows } = await this.db.executeSql(this.getQueuesCommand)
|
|
589
|
+
return rows
|
|
590
|
+
}
|
|
591
|
+
|
|
581
592
|
async updateQueue (name, options = {}) {
|
|
582
|
-
|
|
593
|
+
Attorney.assertQueueName(name)
|
|
594
|
+
|
|
595
|
+
const { policy = QUEUE_POLICIES.standard } = options
|
|
596
|
+
|
|
597
|
+
assert(policy in QUEUE_POLICIES, `${policy} is not a valid queue policy`)
|
|
583
598
|
|
|
584
599
|
const {
|
|
585
600
|
retryLimit,
|
|
@@ -594,6 +609,7 @@ class Manager extends EventEmitter {
|
|
|
594
609
|
|
|
595
610
|
const params = [
|
|
596
611
|
name,
|
|
612
|
+
policy,
|
|
597
613
|
retryLimit,
|
|
598
614
|
retryDelay,
|
|
599
615
|
retryBackoff,
|
|
@@ -606,7 +622,7 @@ class Manager extends EventEmitter {
|
|
|
606
622
|
}
|
|
607
623
|
|
|
608
624
|
async getQueue (name) {
|
|
609
|
-
|
|
625
|
+
Attorney.assertQueueName(name)
|
|
610
626
|
|
|
611
627
|
const sql = plans.getQueueByName(this.config.schema)
|
|
612
628
|
const result = await this.db.executeSql(sql, [name])
|
|
@@ -638,25 +654,21 @@ class Manager extends EventEmitter {
|
|
|
638
654
|
}
|
|
639
655
|
|
|
640
656
|
async deleteQueue (name) {
|
|
641
|
-
|
|
657
|
+
Attorney.assertQueueName(name)
|
|
642
658
|
|
|
643
659
|
const queueSql = plans.getQueueByName(this.config.schema)
|
|
644
660
|
const { rows } = await this.db.executeSql(queueSql, [name])
|
|
645
661
|
|
|
646
662
|
if (rows.length) {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
await this.db.executeSql(sql)
|
|
663
|
+
await this.db.executeSql(plans.dropPartition(this.config.schema, name))
|
|
664
|
+
await this.db.executeSql(plans.deleteQueueRecords(this.config.schema), [name])
|
|
650
665
|
}
|
|
651
|
-
|
|
652
|
-
const sql = plans.deleteQueueRecords(this.config.schema)
|
|
653
|
-
await this.db.executeSql(sql, [name])
|
|
654
666
|
}
|
|
655
667
|
|
|
656
|
-
async purgeQueue (
|
|
657
|
-
|
|
668
|
+
async purgeQueue (name) {
|
|
669
|
+
Attorney.assertQueueName(name)
|
|
658
670
|
const sql = plans.purgeQueue(this.config.schema)
|
|
659
|
-
await this.db.executeSql(sql, [
|
|
671
|
+
await this.db.executeSql(sql, [name])
|
|
660
672
|
}
|
|
661
673
|
|
|
662
674
|
async clearStorage () {
|
|
@@ -664,25 +676,27 @@ class Manager extends EventEmitter {
|
|
|
664
676
|
await this.db.executeSql(sql)
|
|
665
677
|
}
|
|
666
678
|
|
|
667
|
-
async getQueueSize (
|
|
668
|
-
|
|
679
|
+
async getQueueSize (name, options) {
|
|
680
|
+
Attorney.assertQueueName(name)
|
|
669
681
|
|
|
670
682
|
const sql = plans.getQueueSize(this.config.schema, options)
|
|
671
683
|
|
|
672
|
-
const result = await this.db.executeSql(sql, [
|
|
684
|
+
const result = await this.db.executeSql(sql, [name])
|
|
673
685
|
|
|
674
686
|
return result ? parseFloat(result.rows[0].count) : null
|
|
675
687
|
}
|
|
676
688
|
|
|
677
|
-
async getJobById (
|
|
689
|
+
async getJobById (name, id, options = {}) {
|
|
690
|
+
Attorney.assertQueueName(name)
|
|
691
|
+
|
|
678
692
|
const db = options.db || this.db
|
|
679
|
-
const result1 = await db.executeSql(this.getJobByIdCommand, [
|
|
693
|
+
const result1 = await db.executeSql(this.getJobByIdCommand, [name, id])
|
|
680
694
|
|
|
681
695
|
if (result1 && result1.rows && result1.rows.length === 1) {
|
|
682
696
|
return result1.rows[0]
|
|
683
697
|
}
|
|
684
698
|
|
|
685
|
-
const result2 = await db.executeSql(this.getArchivedJobByIdCommand, [
|
|
699
|
+
const result2 = await db.executeSql(this.getArchivedJobByIdCommand, [name, id])
|
|
686
700
|
|
|
687
701
|
if (result2 && result2.rows && result2.rows.length === 1) {
|
|
688
702
|
return result2.rows[0]
|
package/src/plans.js
CHANGED
|
@@ -42,11 +42,12 @@ module.exports = {
|
|
|
42
42
|
archive,
|
|
43
43
|
drop,
|
|
44
44
|
countStates,
|
|
45
|
-
|
|
45
|
+
insertQueue,
|
|
46
46
|
updateQueue,
|
|
47
47
|
createPartition,
|
|
48
48
|
dropPartition,
|
|
49
49
|
deleteQueueRecords,
|
|
50
|
+
getQueues,
|
|
50
51
|
getQueueByName,
|
|
51
52
|
getQueueSize,
|
|
52
53
|
purgeQueue,
|
|
@@ -72,24 +73,18 @@ function create (schema, version) {
|
|
|
72
73
|
createSchema(schema),
|
|
73
74
|
createEnumJobState(schema),
|
|
74
75
|
|
|
76
|
+
createTableVersion(schema),
|
|
77
|
+
createTableQueue(schema),
|
|
78
|
+
createTableSchedule(schema),
|
|
79
|
+
createTableSubscription(schema),
|
|
80
|
+
|
|
75
81
|
createTableJob(schema),
|
|
76
|
-
createIndexJobFetch(schema),
|
|
77
|
-
createIndexJobPolicyStately(schema),
|
|
78
|
-
createIndexJobPolicyShort(schema),
|
|
79
|
-
createIndexJobPolicySingleton(schema),
|
|
80
|
-
createIndexJobThrottleOn(schema),
|
|
81
|
-
createIndexJobThrottleKey(schema),
|
|
82
82
|
|
|
83
83
|
createTableArchive(schema),
|
|
84
84
|
createPrimaryKeyArchive(schema),
|
|
85
85
|
createColumnArchiveArchivedOn(schema),
|
|
86
86
|
createIndexArchiveArchivedOn(schema),
|
|
87
87
|
|
|
88
|
-
createTableVersion(schema),
|
|
89
|
-
createTableQueue(schema),
|
|
90
|
-
createTableSchedule(schema),
|
|
91
|
-
createTableSubscription(schema),
|
|
92
|
-
|
|
93
88
|
getPartitionFunction(schema),
|
|
94
89
|
createPartitionFunction(schema),
|
|
95
90
|
dropPartitionFunction(schema),
|
|
@@ -106,6 +101,21 @@ function createSchema (schema) {
|
|
|
106
101
|
`
|
|
107
102
|
}
|
|
108
103
|
|
|
104
|
+
function createEnumJobState (schema) {
|
|
105
|
+
// ENUM definition order is important
|
|
106
|
+
// base type is numeric and first values are less than last values
|
|
107
|
+
return `
|
|
108
|
+
CREATE TYPE ${schema}.job_state AS ENUM (
|
|
109
|
+
'${JOB_STATES.created}',
|
|
110
|
+
'${JOB_STATES.retry}',
|
|
111
|
+
'${JOB_STATES.active}',
|
|
112
|
+
'${JOB_STATES.completed}',
|
|
113
|
+
'${JOB_STATES.cancelled}',
|
|
114
|
+
'${JOB_STATES.failed}'
|
|
115
|
+
)
|
|
116
|
+
`
|
|
117
|
+
}
|
|
118
|
+
|
|
109
119
|
function createTableVersion (schema) {
|
|
110
120
|
return `
|
|
111
121
|
CREATE TABLE ${schema}.version (
|
|
@@ -117,17 +127,46 @@ function createTableVersion (schema) {
|
|
|
117
127
|
`
|
|
118
128
|
}
|
|
119
129
|
|
|
120
|
-
function
|
|
121
|
-
// ENUM definition order is important
|
|
122
|
-
// base type is numeric and first values are less than last values
|
|
130
|
+
function createTableQueue (schema) {
|
|
123
131
|
return `
|
|
124
|
-
CREATE
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
132
|
+
CREATE TABLE ${schema}.queue (
|
|
133
|
+
name text,
|
|
134
|
+
policy text,
|
|
135
|
+
retry_limit int,
|
|
136
|
+
retry_delay int,
|
|
137
|
+
retry_backoff bool,
|
|
138
|
+
expire_seconds int,
|
|
139
|
+
retention_minutes int,
|
|
140
|
+
dead_letter text,
|
|
141
|
+
created_on timestamp with time zone not null default now(),
|
|
142
|
+
PRIMARY KEY (name)
|
|
143
|
+
)
|
|
144
|
+
`
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function createTableSchedule (schema) {
|
|
148
|
+
return `
|
|
149
|
+
CREATE TABLE ${schema}.schedule (
|
|
150
|
+
name text REFERENCES ${schema}.queue ON DELETE CASCADE,
|
|
151
|
+
cron text not null,
|
|
152
|
+
timezone text,
|
|
153
|
+
data jsonb,
|
|
154
|
+
options jsonb,
|
|
155
|
+
created_on timestamp with time zone not null default now(),
|
|
156
|
+
updated_on timestamp with time zone not null default now(),
|
|
157
|
+
PRIMARY KEY (name)
|
|
158
|
+
)
|
|
159
|
+
`
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function createTableSubscription (schema) {
|
|
163
|
+
return `
|
|
164
|
+
CREATE TABLE ${schema}.subscription (
|
|
165
|
+
event text not null,
|
|
166
|
+
name text not null REFERENCES ${schema}.queue ON DELETE CASCADE,
|
|
167
|
+
created_on timestamp with time zone not null default now(),
|
|
168
|
+
updated_on timestamp with time zone not null default now(),
|
|
169
|
+
PRIMARY KEY(event, name)
|
|
131
170
|
)
|
|
132
171
|
`
|
|
133
172
|
}
|
|
@@ -154,8 +193,7 @@ function createTableJob (schema) {
|
|
|
154
193
|
keep_until timestamp with time zone NOT NULL default now() + interval '14 days',
|
|
155
194
|
output jsonb,
|
|
156
195
|
dead_letter text,
|
|
157
|
-
policy text
|
|
158
|
-
CONSTRAINT job_pkey PRIMARY KEY (name, id)
|
|
196
|
+
policy text
|
|
159
197
|
) PARTITION BY LIST (name)
|
|
160
198
|
`
|
|
161
199
|
}
|
|
@@ -186,7 +224,7 @@ function getPartitionFunction (schema) {
|
|
|
186
224
|
return `
|
|
187
225
|
CREATE FUNCTION ${schema}.get_partition(queue_name text, out name text) AS
|
|
188
226
|
$$
|
|
189
|
-
SELECT '
|
|
227
|
+
SELECT 'j' || left(regexp_replace(queue_name, '\\W', '', 'g'),10) || left(encode(sha224(queue_name::bytea), 'hex'),10);
|
|
190
228
|
$$
|
|
191
229
|
LANGUAGE SQL
|
|
192
230
|
IMMUTABLE
|
|
@@ -201,8 +239,18 @@ function createPartitionFunction (schema) {
|
|
|
201
239
|
DECLARE
|
|
202
240
|
table_name varchar := ${schema}.get_partition(queue_name);
|
|
203
241
|
BEGIN
|
|
204
|
-
EXECUTE format('CREATE TABLE ${schema}.%I (LIKE ${schema}.job INCLUDING DEFAULTS
|
|
205
|
-
|
|
242
|
+
EXECUTE format('CREATE TABLE ${schema}.%I (LIKE ${schema}.job INCLUDING DEFAULTS)', table_name);
|
|
243
|
+
|
|
244
|
+
EXECUTE format('${formatPartitionCommand(createPrimaryKeyJob(schema))}', table_name);
|
|
245
|
+
EXECUTE format('${formatPartitionCommand(createQueueForeignKeyJob(schema))}', table_name);
|
|
246
|
+
EXECUTE format('${formatPartitionCommand(createQueueForeignKeyJobDeadLetter(schema))}', table_name);
|
|
247
|
+
EXECUTE format('${formatPartitionCommand(createIndexJobPolicyShort(schema))}', table_name);
|
|
248
|
+
EXECUTE format('${formatPartitionCommand(createIndexJobPolicySingleton(schema))}', table_name);
|
|
249
|
+
EXECUTE format('${formatPartitionCommand(createIndexJobPolicyStately(schema))}', table_name);
|
|
250
|
+
EXECUTE format('${formatPartitionCommand(createIndexJobThrottle(schema))}', table_name);
|
|
251
|
+
EXECUTE format('${formatPartitionCommand(createIndexJobFetch(schema))}', table_name);
|
|
252
|
+
|
|
253
|
+
EXECUTE format('ALTER TABLE ${schema}.%I ADD CONSTRAINT cjc CHECK (name=%L)', table_name, queue_name);
|
|
206
254
|
EXECUTE format('ALTER TABLE ${schema}.job ATTACH PARTITION ${schema}.%I FOR VALUES IN (%L)', table_name, queue_name);
|
|
207
255
|
END;
|
|
208
256
|
$$
|
|
@@ -210,13 +258,17 @@ function createPartitionFunction (schema) {
|
|
|
210
258
|
`
|
|
211
259
|
}
|
|
212
260
|
|
|
261
|
+
function formatPartitionCommand (command) {
|
|
262
|
+
return command.replace('.job', '.%1$I').replace('job_idx', '%1$s_idx').replaceAll('\'', '\'\'')
|
|
263
|
+
}
|
|
264
|
+
|
|
213
265
|
function dropPartitionFunction (schema) {
|
|
214
266
|
return `
|
|
215
267
|
CREATE FUNCTION ${schema}.drop_partition(queue_name text)
|
|
216
268
|
RETURNS VOID AS
|
|
217
269
|
$$
|
|
218
270
|
BEGIN
|
|
219
|
-
EXECUTE format('DROP TABLE IF EXISTS
|
|
271
|
+
EXECUTE format('DROP TABLE IF EXISTS ${schema}.%I', ${schema}.get_partition(queue_name));
|
|
220
272
|
END;
|
|
221
273
|
$$
|
|
222
274
|
LANGUAGE plpgsql;
|
|
@@ -227,34 +279,40 @@ function dropPartition (schema, name) {
|
|
|
227
279
|
return `SELECT ${schema}.drop_partition('${name}');`
|
|
228
280
|
}
|
|
229
281
|
|
|
282
|
+
function createPrimaryKeyJob (schema) {
|
|
283
|
+
return `ALTER TABLE ${schema}.job ADD PRIMARY KEY (name, id)`
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function createQueueForeignKeyJob (schema) {
|
|
287
|
+
return `ALTER TABLE ${schema}.job ADD FOREIGN KEY (name) REFERENCES ${schema}.queue (name) ON DELETE RESTRICT`
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function createQueueForeignKeyJobDeadLetter (schema) {
|
|
291
|
+
return `ALTER TABLE ${schema}.job ADD FOREIGN KEY (dead_letter) REFERENCES ${schema}.queue (name) ON DELETE RESTRICT`
|
|
292
|
+
}
|
|
293
|
+
|
|
230
294
|
function createPrimaryKeyArchive (schema) {
|
|
231
|
-
return `ALTER TABLE ${schema}.archive ADD
|
|
295
|
+
return `ALTER TABLE ${schema}.archive ADD PRIMARY KEY (name, id)`
|
|
232
296
|
}
|
|
233
297
|
|
|
234
298
|
function createIndexJobPolicyShort (schema) {
|
|
235
|
-
|
|
236
|
-
return `CREATE UNIQUE INDEX job_policy_short ON ${schema}.job (name) WHERE state = '${JOB_STATES.created}' AND policy = '${QUEUE_POLICIES.short}'`
|
|
299
|
+
return `CREATE UNIQUE INDEX job_idx_psh ON ${schema}.job (name, COALESCE(singleton_key, '')) WHERE state = '${JOB_STATES.created}' AND policy = '${QUEUE_POLICIES.short}';`
|
|
237
300
|
}
|
|
238
301
|
|
|
239
302
|
function createIndexJobPolicySingleton (schema) {
|
|
240
|
-
return `CREATE UNIQUE INDEX
|
|
303
|
+
return `CREATE UNIQUE INDEX job_idx_psi ON ${schema}.job (name, COALESCE(singleton_key, '')) WHERE state = '${JOB_STATES.active}' AND policy = '${QUEUE_POLICIES.singleton}'`
|
|
241
304
|
}
|
|
242
305
|
|
|
243
306
|
function createIndexJobPolicyStately (schema) {
|
|
244
|
-
return `CREATE UNIQUE INDEX
|
|
307
|
+
return `CREATE UNIQUE INDEX job_idx_pst ON ${schema}.job (name, state, COALESCE(singleton_key, '')) WHERE state <= '${JOB_STATES.active}' AND policy = '${QUEUE_POLICIES.stately}'`
|
|
245
308
|
}
|
|
246
309
|
|
|
247
|
-
function
|
|
248
|
-
return `CREATE UNIQUE INDEX
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function createIndexJobThrottleKey (schema) {
|
|
252
|
-
// how useful is this really?
|
|
253
|
-
return `CREATE UNIQUE INDEX job_throttle_key ON ${schema}.job (name, singleton_key) WHERE state <= '${JOB_STATES.completed}' AND singleton_on IS NULL`
|
|
310
|
+
function createIndexJobThrottle (schema) {
|
|
311
|
+
return `CREATE UNIQUE INDEX job_idx_to ON ${schema}.job (name, singleton_on, COALESCE(singleton_key, '')) WHERE state <> '${JOB_STATES.cancelled}' AND singleton_on IS NOT NULL`
|
|
254
312
|
}
|
|
255
313
|
|
|
256
314
|
function createIndexJobFetch (schema) {
|
|
257
|
-
return `CREATE INDEX
|
|
315
|
+
return `CREATE INDEX job_idx_f ON ${schema}.job (name, start_after) INCLUDE (priority, created_on, id) WHERE state < '${JOB_STATES.active}'`
|
|
258
316
|
}
|
|
259
317
|
|
|
260
318
|
function createTableArchive (schema) {
|
|
@@ -266,7 +324,7 @@ function createColumnArchiveArchivedOn (schema) {
|
|
|
266
324
|
}
|
|
267
325
|
|
|
268
326
|
function createIndexArchiveArchivedOn (schema) {
|
|
269
|
-
return `CREATE INDEX
|
|
327
|
+
return `CREATE INDEX archive_idx_ao ON ${schema}.archive(archived_on)`
|
|
270
328
|
}
|
|
271
329
|
|
|
272
330
|
function trySetMaintenanceTime (schema) {
|
|
@@ -289,7 +347,7 @@ function trySetTimestamp (schema, column) {
|
|
|
289
347
|
`
|
|
290
348
|
}
|
|
291
349
|
|
|
292
|
-
function
|
|
350
|
+
function insertQueue (schema) {
|
|
293
351
|
return `
|
|
294
352
|
INSERT INTO ${schema}.queue (name, policy, retry_limit, retry_delay, retry_backoff, expire_seconds, retention_minutes, dead_letter)
|
|
295
353
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
@@ -299,28 +357,27 @@ function createQueue (schema) {
|
|
|
299
357
|
function updateQueue (schema) {
|
|
300
358
|
return `
|
|
301
359
|
UPDATE ${schema}.queue SET
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
360
|
+
policy = COALESCE($2, policy),
|
|
361
|
+
retry_limit = COALESCE($3, retry_limit),
|
|
362
|
+
retry_delay = COALESCE($4, retry_delay),
|
|
363
|
+
retry_backoff = COALESCE($5, retry_backoff),
|
|
364
|
+
expire_seconds = COALESCE($6, expire_seconds),
|
|
365
|
+
retention_minutes = COALESCE($7, retention_minutes),
|
|
366
|
+
dead_letter = COALESCE($8, dead_letter)
|
|
308
367
|
WHERE name = $1
|
|
309
368
|
`
|
|
310
369
|
}
|
|
311
370
|
|
|
371
|
+
function getQueues (schema) {
|
|
372
|
+
return `SELECT * FROM ${schema}.queue`
|
|
373
|
+
}
|
|
374
|
+
|
|
312
375
|
function getQueueByName (schema) {
|
|
313
376
|
return `SELECT * FROM ${schema}.queue WHERE name = $1`
|
|
314
377
|
}
|
|
315
378
|
|
|
316
379
|
function deleteQueueRecords (schema) {
|
|
317
|
-
return `
|
|
318
|
-
DELETE FROM ${schema}.queue WHERE name = $1
|
|
319
|
-
), ds AS (
|
|
320
|
-
DELETE FROM ${schema}.schedule WHERE name = $1
|
|
321
|
-
)
|
|
322
|
-
DELETE FROM ${schema}.job WHERE name = $1
|
|
323
|
-
`
|
|
380
|
+
return `DELETE FROM ${schema}.queue WHERE name = $1`
|
|
324
381
|
}
|
|
325
382
|
|
|
326
383
|
function purgeQueue (schema) {
|
|
@@ -337,54 +394,8 @@ function getQueueSize (schema, options = {}) {
|
|
|
337
394
|
return `SELECT count(*) as count FROM ${schema}.job WHERE name = $1 AND state < '${options.before}'`
|
|
338
395
|
}
|
|
339
396
|
|
|
340
|
-
function createTableQueue (schema) {
|
|
341
|
-
return `
|
|
342
|
-
CREATE TABLE ${schema}.queue (
|
|
343
|
-
name text primary key,
|
|
344
|
-
policy text,
|
|
345
|
-
retry_limit int,
|
|
346
|
-
retry_delay int,
|
|
347
|
-
retry_backoff bool,
|
|
348
|
-
expire_seconds int,
|
|
349
|
-
retention_minutes int,
|
|
350
|
-
dead_letter text,
|
|
351
|
-
created_on timestamp with time zone not null default now()
|
|
352
|
-
)
|
|
353
|
-
`
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function createTableSchedule (schema) {
|
|
357
|
-
return `
|
|
358
|
-
CREATE TABLE ${schema}.schedule (
|
|
359
|
-
name text primary key,
|
|
360
|
-
cron text not null,
|
|
361
|
-
timezone text,
|
|
362
|
-
data jsonb,
|
|
363
|
-
options jsonb,
|
|
364
|
-
created_on timestamp with time zone not null default now(),
|
|
365
|
-
updated_on timestamp with time zone not null default now()
|
|
366
|
-
)
|
|
367
|
-
`
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function createTableSubscription (schema) {
|
|
371
|
-
return `
|
|
372
|
-
CREATE TABLE ${schema}.subscription (
|
|
373
|
-
event text not null,
|
|
374
|
-
name text not null,
|
|
375
|
-
created_on timestamp with time zone not null default now(),
|
|
376
|
-
updated_on timestamp with time zone not null default now(),
|
|
377
|
-
PRIMARY KEY(event, name)
|
|
378
|
-
)
|
|
379
|
-
`
|
|
380
|
-
}
|
|
381
|
-
|
|
382
397
|
function getSchedules (schema) {
|
|
383
|
-
return `
|
|
384
|
-
SELECT s.*
|
|
385
|
-
FROM ${schema}.schedule s
|
|
386
|
-
JOIN ${schema}.queue q on s.name = q.name
|
|
387
|
-
`
|
|
398
|
+
return `SELECT * FROM ${schema}.schedule`
|
|
388
399
|
}
|
|
389
400
|
|
|
390
401
|
function schedule (schema) {
|
package/types.d.ts
CHANGED
|
@@ -113,9 +113,9 @@ declare namespace PgBoss {
|
|
|
113
113
|
type SendOptions = JobOptions & ExpirationOptions & RetentionOptions & RetryOptions & ConnectionOptions;
|
|
114
114
|
|
|
115
115
|
type QueuePolicy = 'standard' | 'short' | 'singleton' | 'stately'
|
|
116
|
-
|
|
117
|
-
type
|
|
118
|
-
|
|
116
|
+
|
|
117
|
+
type Queue = RetryOptions & ExpirationOptions & RetentionOptions & { name: string, policy: QueuePolicy, deadLetter?: string }
|
|
118
|
+
|
|
119
119
|
type ScheduleOptions = SendOptions & { tz?: string }
|
|
120
120
|
|
|
121
121
|
interface JobPollingOptions {
|
|
@@ -370,7 +370,8 @@ declare class PgBoss extends EventEmitter {
|
|
|
370
370
|
|
|
371
371
|
createQueue(name: string, options?: PgBoss.Queue): Promise<void>;
|
|
372
372
|
getQueue(name: string): Promise<PgBoss.Queue | null>;
|
|
373
|
-
|
|
373
|
+
getQueues(): Promise<[PgBoss.Queue]>;
|
|
374
|
+
updateQueue(name: string, options?: PgBoss.Queue): Promise<void>;
|
|
374
375
|
deleteQueue(name: string): Promise<void>;
|
|
375
376
|
purgeQueue(name: string): Promise<void>;
|
|
376
377
|
|