Skip to content

Commit

Permalink
10.0.3 fixes (#477)
Browse files Browse the repository at this point in the history
* fix priority bypass and reduced worker delay threshold

* versioning and deps
  • Loading branch information
timgit authored Aug 27, 2024
1 parent e75152b commit a7334db
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 50 deletions.
80 changes: 40 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-boss",
"version": "10.0.2",
"version": "10.0.3",
"description": "Queueing jobs in Postgres from Node.js like a boss",
"main": "./src/index.js",
"engines": {
Expand Down
20 changes: 13 additions & 7 deletions src/attorney.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const assert = require('assert')
const { DEFAULT_SCHEMA } = require('./plans')

const POLICY = {
MAX_EXPIRATION_HOURS: 24,
MIN_POLLING_INTERVAL_MS: 500
}

module.exports = {
POLICY,
getConfig,
checkSendArgs,
checkQueueArgs,
Expand All @@ -12,8 +18,6 @@ module.exports = {
assertQueueName
}

const MAX_INTERVAL_HOURS = 24

const WARNINGS = {
CLOCK_SKEW: {
message: 'Timekeeper detected clock skew between this instance and the database server. This will not affect scheduling operations, but this warning is shown any time the skew exceeds 60 seconds.',
Expand Down Expand Up @@ -262,7 +266,7 @@ function applyExpirationConfig (config, defaults = {}) {
? config.expireInSeconds
: null

assert(!expireIn || expireIn / 60 / 60 < MAX_INTERVAL_HOURS, `configuration assert: expiration cannot exceed ${MAX_INTERVAL_HOURS} hours`)
assert(!expireIn || expireIn / 60 / 60 < POLICY.MAX_EXPIRATION_HOURS, `configuration assert: expiration cannot exceed ${POLICY.MAX_EXPIRATION_HOURS} hours`)

config.expireIn = expireIn
config.expireInDefault = defaults?.expireIn
Expand All @@ -279,8 +283,8 @@ function applyRetryConfig (config, defaults) {
}

function applyPollingInterval (config, defaults) {
assert(!('pollingIntervalSeconds' in config) || config.pollingIntervalSeconds >= 0.5,
'configuration assert: pollingIntervalSeconds must be at least every 500ms')
assert(!('pollingIntervalSeconds' in config) || config.pollingIntervalSeconds >= POLICY.MIN_POLLING_INTERVAL_MS / 1000,
`configuration assert: pollingIntervalSeconds must be at least every ${POLICY.MIN_POLLING_INTERVAL_MS}ms`)

config.pollingInterval = ('pollingIntervalSeconds' in config)
? config.pollingIntervalSeconds * 1000
Expand All @@ -300,7 +304,8 @@ function applyMaintenanceConfig (config) {
? config.maintenanceIntervalSeconds
: 120

assert(config.maintenanceIntervalSeconds / 60 / 60 < MAX_INTERVAL_HOURS, `configuration assert: maintenance interval cannot exceed ${MAX_INTERVAL_HOURS} hours`)
assert(config.maintenanceIntervalSeconds / 60 / 60 < POLICY.MAX_EXPIRATION_HOURS,
`configuration assert: maintenance interval cannot exceed ${POLICY.MAX_EXPIRATION_HOURS} hours`)
}

function applyDeleteConfig (config) {
Expand Down Expand Up @@ -344,7 +349,8 @@ function applyMonitoringConfig (config) {
: null

if (config.monitorStateIntervalSeconds) {
assert(config.monitorStateIntervalSeconds / 60 / 60 < MAX_INTERVAL_HOURS, `configuration assert: state monitoring interval cannot exceed ${MAX_INTERVAL_HOURS} hours`)
assert(config.monitorStateIntervalSeconds / 60 / 60 < POLICY.MAX_EXPIRATION_HOURS,
`configuration assert: state monitoring interval cannot exceed ${POLICY.MAX_EXPIRATION_HOURS} hours`)
}

const TEN_MINUTES_IN_SECONDS = 600
Expand Down
2 changes: 1 addition & 1 deletion src/plans.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ function fetchNextJob (schema) {
WHERE name = $1
AND state < '${JOB_STATES.active}'
AND start_after < now()
ORDER BY ${priority && 'priority desc, '} created_on, id
ORDER BY ${priority ? 'priority desc, ' : ''}created_on, id
LIMIT $2
FOR UPDATE SKIP LOCKED
)
Expand Down
2 changes: 1 addition & 1 deletion src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Worker {

this.lastJobDuration = duration

if (!this.stopping && !this.beenNotified && (this.interval - duration > 500)) {
if (!this.stopping && !this.beenNotified && (this.interval - duration) > 100) {
this.loopDelayPromise = delay(this.interval - duration)
await this.loopDelayPromise
this.loopDelayPromise = null
Expand Down
17 changes: 17 additions & 0 deletions test/priorityTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,21 @@ describe('priority', function () {
assert.strictEqual(job2.id, medium)
assert.strictEqual(job3.id, low)
})

it('bypasses priority when priority option used in fetch', async function () {
const boss = this.test.boss = await helper.start({ ...this.test.bossConfig })
const queue = this.test.bossConfig.schema

const low = await boss.send(queue, null, { priority: 1 })
const medium = await boss.send(queue, null, { priority: 5 })
const high = await boss.send(queue, null, { priority: 10 })

const [job1] = await boss.fetch(queue, { priority: false })
const [job2] = await boss.fetch(queue, { priority: false })
const [job3] = await boss.fetch(queue, { priority: false })

assert.strictEqual(job1.id, low)
assert.strictEqual(job2.id, medium)
assert.strictEqual(job3.id, high)
})
})

0 comments on commit a7334db

Please sign in to comment.