@@ -117,13 +117,15 @@ async function scheduleCronJobs(
117
117
jobsAndIdentifiers : JobAndCronIdentifier [ ] ,
118
118
ts : string ,
119
119
useNodeTime : boolean ,
120
+ workerSchema : string ,
121
+ preparedStatements : boolean ,
120
122
) {
121
123
// TODO: refactor this to use `add_jobs`
122
124
123
125
// Note that `identifier` is guaranteed to be unique for every record
124
126
// in `specs`.
125
- await pgPool . query (
126
- `
127
+ await pgPool . query ( {
128
+ text : `
127
129
with specs as (
128
130
select
129
131
index,
@@ -166,26 +168,45 @@ async function scheduleCronJobs(
166
168
inner join locks on (locks.identifier = specs.identifier)
167
169
order by specs.index asc
168
170
` ,
169
- [
171
+ values : [
170
172
JSON . stringify ( jobsAndIdentifiers ) ,
171
173
ts ,
172
174
useNodeTime ? new Date ( ) . toISOString ( ) : null ,
173
175
] ,
174
- ) ;
176
+ name : ! preparedStatements
177
+ ? undefined
178
+ : `cron${ useNodeTime ? "N" : "" } /${ workerSchema } ` ,
179
+ } ) ;
175
180
}
176
181
177
182
/**
178
183
* Marks any previously unknown crontab identifiers as now being known. Then
179
184
* performs backfilling on any crontab tasks that need it.
180
185
*/
181
- async function registerAndBackfillItems (
182
- ctx : CompiledSharedOptions ,
183
- { pgPool, events, cron } : { pgPool : Pool ; events : WorkerEvents ; cron : Cron } ,
184
- escapedWorkerSchema : string ,
185
- parsedCronItems : ParsedCronItem [ ] ,
186
- startTime : Date ,
187
- useNodeTime : boolean ,
188
- ) {
186
+ async function registerAndBackfillItems ( details : {
187
+ ctx : CompiledSharedOptions ;
188
+ pgPool : Pool ;
189
+ events : WorkerEvents ;
190
+ cron : Cron ;
191
+ workerSchema : string ;
192
+ preparedStatements : boolean ;
193
+ escapedWorkerSchema : string ;
194
+ parsedCronItems : ParsedCronItem [ ] ;
195
+ startTime : Date ;
196
+ useNodeTime : boolean ;
197
+ } ) {
198
+ const {
199
+ ctx,
200
+ pgPool,
201
+ events,
202
+ cron,
203
+ workerSchema,
204
+ preparedStatements,
205
+ escapedWorkerSchema,
206
+ parsedCronItems,
207
+ startTime,
208
+ useNodeTime,
209
+ } = details ;
189
210
// First, scan the DB to get our starting point.
190
211
const { rows } = await pgPool . query < KnownCrontab > (
191
212
`SELECT * FROM ${ escapedWorkerSchema } ._private_known_crontabs as known_crontabs` ,
@@ -273,6 +294,8 @@ async function registerAndBackfillItems(
273
294
itemsToBackfill ,
274
295
ts ,
275
296
useNodeTime ,
297
+ workerSchema ,
298
+ preparedStatements ,
276
299
) ;
277
300
}
278
301
@@ -305,9 +328,10 @@ export const runCron = (
305
328
const {
306
329
logger,
307
330
escapedWorkerSchema,
331
+ workerSchema,
308
332
events,
309
333
resolvedPreset : {
310
- worker : { useNodeTime } ,
334
+ worker : { useNodeTime, preparedStatements = true } ,
311
335
} ,
312
336
} = compiledSharedOptions ;
313
337
@@ -345,14 +369,18 @@ export const runCron = (
345
369
346
370
// We must backfill BEFORE scheduling any new jobs otherwise backfill won't
347
371
// work due to known_crontabs.last_execution having been updated.
348
- await registerAndBackfillItems (
372
+ await registerAndBackfillItems ( {
349
373
ctx,
350
- { pgPool, events, cron } ,
374
+ pgPool,
375
+ events,
376
+ cron,
377
+ workerSchema,
378
+ preparedStatements,
351
379
escapedWorkerSchema,
352
380
parsedCronItems,
353
- new Date ( + start ) ,
381
+ startTime : new Date ( + start ) ,
354
382
useNodeTime,
355
- ) ;
383
+ } ) ;
356
384
357
385
events . emit ( "cron:started" , { ctx, cron, start } ) ;
358
386
@@ -466,6 +494,8 @@ export const runCron = (
466
494
jobsAndIdentifiers ,
467
495
ts ,
468
496
useNodeTime ,
497
+ workerSchema ,
498
+ preparedStatements ,
469
499
) ;
470
500
events . emit ( "cron:scheduled" , {
471
501
ctx,
0 commit comments