timgit / pg-boss

Queueing jobs in Node.js using PostgreSQL like a boss
MIT License
1.73k stars 144 forks source link

Maintenance Interval Issues / config options ignored #405

Closed bentron2000 closed 11 months ago

bentron2000 commented 1 year ago

Description

I'm coming across a few issues relating to the maintenance schedule and other config options

  1. maintenanceIntervalSeconds I cannot set the maintenance interval to anything manually - no matter what I try, the interval seems to be ~3mins.

  2. archiveCompletedAfterSeconds Even when the maintenance event runs, the completed jobs are not being archived. (even after the default 12 hours)

  3. Each time an instance is started, maintenance runs (the 'maintenance' event is fired at least) - however the archiveCompletedAfterSeconds is not honoured and the table just fills up wtih __pgboss__maintenance and __pgboss__cron jobs.

    Environment:

    node: v16.13.0 PostgreSQL: 15.2 pgcrypto: 1.3


Code:

const PgBoss = require('pg-boss')

const params = {
  ...
}

const boss = new PgBoss(params, {
  maintenanceIntervalSeconds: 2,
  archiveCompletedAfterSeconds: 61,
  retentionSeconds: 2,
  expireInSeconds: 10
})

boss.on('error', console.error)

boss.on('maintenance', arg => {
  console.log('MAINTENANCE', new Date().toString(), arg)
})

const main = async () => {
  await boss.start()

  await boss.send('test', { herp: 'derp' })
  await boss.send('test', { herp: 'derp' })
  await boss.send('test', { herp: 'derp' })

  await boss.fetch('test').then(job => boss.complete(job.id))
  await boss.fetch('test').then(job => boss.complete(job.id))
  await boss.fetch('test').then(job => boss.complete(job.id))
}

main()

Output

Start process ~17:41:00 (ish) left running for a while

MAINTENANCE Thu Jun 22 2023 17:41:12 GMT+1000 (Australian Eastern Standard Time) { ms: 5 }
MAINTENANCE Thu Jun 22 2023 17:44:12 GMT+1000 (Australian Eastern Standard Time) { ms: 17 }
MAINTENANCE Thu Jun 22 2023 17:47:12 GMT+1000 (Australian Eastern Standard Time) { ms: 11 }
MAINTENANCE Thu Jun 22 2023 17:50:12 GMT+1000 (Australian Eastern Standard Time) { ms: 15 }
MAINTENANCE Thu Jun 22 2023 17:53:12 GMT+1000 (Australian Eastern Standard Time) { ms: 12 }

Database

Jobs DB table dump csv data-1687420537262.csv

timgit commented 11 months ago

Your options should not be in a 2nd argument. The test suite uses these options as an example.