Skip to content

Commit

Permalink
Merge pull request #332 from timgit/v8
Browse files Browse the repository at this point in the history
v8
  • Loading branch information
timgit authored Aug 3, 2022
2 parents b852e18 + 5f34a07 commit c4bcaab
Show file tree
Hide file tree
Showing 13 changed files with 1,478 additions and 1,692 deletions.
31 changes: 21 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
sudo: required
dist: trusty
addons:
postgresql: "9.5"
services:
- postgresql
# from: https://travis-ci.community/t/update-postgresql-version-to-13-in-travisci/12884
dist: focal
language: node_js
node_js:
- "16"
- "14"
- "12"
- '18'
- '16'
- '14'
addons:
postgresql: '13'
apt:
packages:
- postgresql-13
env:
global:
- PGHOST=localhost
- PGPORT=5432
- PGUSER=postgres
before_install:
- sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
- sudo service postgresql restart
- sleep 1
- postgres --version
before_script:
- psql -c 'create database pgboss' -U postgres
- psql -c 'create extension pgcrypto' -d pgboss -U postgres
- psql -c 'create extension pgcrypto' -U postgres -d pgboss
script:
- npm run forcover
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ This will likely cater the most to teams already familiar with the simplicity of
* Automatic maintenance operations to manage table growth

## Requirements
* Node 12 or higher
* Node 14 or higher
* PostgreSQL 9.5 or higher

## Installation
Expand Down
3,075 changes: 1,418 additions & 1,657 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
{
"name": "pg-boss",
"version": "7.4.0",
"version": "8.0.0",
"description": "Queueing jobs in Node.js using PostgreSQL like a boss",
"main": "./src/index.js",
"engines": {
"node": ">=12.0.0"
"node": ">=14"
},
"dependencies": {
"cron-parser": "^4.0.0",
"delay": "^5.0.0",
"lodash.debounce": "^4.0.8",
"p-map": "^4.0.0",
"p-map": "^5.3.0",
"pg": "^8.5.1",
"serialize-error": "^11.0.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/node": "^17.0.2",
"@types/node": "^18.0.0",
"coveralls": "^3.1.0",
"luxon": "^2.0.1",
"mocha": "^9.0.1",
"luxon": "^3.0.1",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"standard": "^16.0.3"
"standard": "^17.0.0"
},
"scripts": {
"test": "standard && mocha",
"cover": "nyc --reporter=text npm test",
"forcover": "npm run cover && nyc report --reporter=text-lcov | coveralls",
"travis-cover": "nyc --reporter=text npm run travis-test",
"travis-test": "standard && mocha --jobs 0 --exit",
"forcover": "npm run travis-cover && nyc report --reporter=text-lcov | coveralls",
"export-schema": "node ./scripts/construct.js",
"export-migration": "node ./scripts/migrate.js",
"export-rollback": "node ./scripts/rollback.js",
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class PgBoss extends EventEmitter {
}

async start () {
const { serializeError } = await import('serialize-error')

if (!this.stopped) {
return this
}
Expand All @@ -104,7 +106,7 @@ class PgBoss extends EventEmitter {

this.started = true

this.manager.start()
this.manager.start({ stringify: serializeError })

if (!this.config.noSupervisor) {
await this.boss.supervise()
Expand Down
18 changes: 9 additions & 9 deletions src/manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const assert = require('assert')
const EventEmitter = require('events')
const pMap = require('p-map')
const delay = require('delay')
const uuid = require('uuid')
const debounce = require('lodash.debounce')
Expand Down Expand Up @@ -45,6 +44,8 @@ class Manager extends EventEmitter {
constructor (db, config) {
super()

this.stringify = null

this.config = config
this.db = db

Expand Down Expand Up @@ -97,7 +98,8 @@ class Manager extends EventEmitter {
this.emitWipThrottled = debounce(() => this.emit(events.wip, this.getWipData()), WIP_EVENT_INTERVAL, WIP_DEBOUNCE_OPTIONS)
}

start () {
start ({ stringify }) {
this.stringify = stringify
this.stopping = false
}

Expand Down Expand Up @@ -211,6 +213,8 @@ class Manager extends EventEmitter {
const fetch = () => this.fetch(name, batchSize || (teamSize - queueSize), { includeMetadata })

const onFetch = async (jobs) => {
const { default: pMap } = await import('p-map')

if (this.config.__test__throw_worker) {
throw new Error('__test__throw_worker')
}
Expand Down Expand Up @@ -516,15 +520,11 @@ class Manager extends EventEmitter {
mapCompletionDataArg (data) {
if (data === null || typeof data === 'undefined' || typeof data === 'function') { return null }

if (data instanceof Error) {
const newData = {}
Object.getOwnPropertyNames(data).forEach(key => { newData[key] = data[key] })
data = newData
}

return (typeof data === 'object' && !Array.isArray(data))
const result = (typeof data === 'object' && !Array.isArray(data))
? data
: { value: data }

return this.stringify(result)
}

mapCompletionResponse (ids, result) {
Expand Down
1 change: 1 addition & 0 deletions src/plans.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function locked (schema, query) {

return `
BEGIN;
SET LOCAL statement_timeout = '30s';
${advisoryLock(schema)};
${query};
COMMIT;
Expand Down
3 changes: 2 additions & 1 deletion src/timekeeper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const pMap = require('p-map')
const EventEmitter = require('events')
const plans = require('./plans')
const cronParser = require('cron-parser')
Expand Down Expand Up @@ -126,6 +125,8 @@ class Timekeeper extends EventEmitter {
async onCron () {
if (this.stopped) return

const { default: pMap } = await import('p-map')

try {
if (this.config.__test__throw_clock_monitoring) {
throw new Error('clock monitoring error')
Expand Down
3 changes: 2 additions & 1 deletion test/failureTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const delay = require('delay')
const assert = require('assert')
const helper = require('./testHelper')
const pMap = require('p-map')

describe('failure', function () {
it('should reject missing id argument', async function () {
Expand Down Expand Up @@ -61,6 +60,8 @@ describe('failure', function () {
})

it('should fail a batch of jobs with a data arg', async function () {
const { default: pMap } = await import('p-map')

const boss = this.test.boss = await helper.start(this.test.bossConfig)
const queue = this.test.bossConfig.schema
const message = 'some error'
Expand Down
2 changes: 1 addition & 1 deletion test/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function afterEach () {
if (boss) {
await new Promise((resolve) => {
boss.on('stopped', resolve)
helper.stop(boss, 2000)
helper.stop(boss)
})
}

Expand Down
7 changes: 5 additions & 2 deletions test/multiMasterTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const assert = require('assert')
const pMap = require('p-map')
const delay = require('delay')
const helper = require('./testHelper')
const PgBoss = require('../')
Expand All @@ -9,6 +8,8 @@ const currentSchemaVersion = require('../version.json').schema

describe('multi-master', function () {
it('should only allow 1 master to start at a time', async function () {
const { default: pMap } = await import('p-map')

const replicaCount = 20
const config = { ...this.test.bossConfig, noSupervisor: true, max: 2 }
const instances = []
Expand All @@ -27,7 +28,9 @@ describe('multi-master', function () {
})

it('should only allow 1 master to migrate to latest at a time', async function () {
const replicaCount = 20
const { default: pMap } = await import('p-map')

const replicaCount = 5
const config = { ...this.test.bossConfig, noSupervisor: true, max: 2 }

const db = await helper.getDb()
Expand Down
3 changes: 2 additions & 1 deletion test/speedTest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const pMap = require('p-map')
const helper = require('./testHelper')

describe('speed', function () {
Expand All @@ -13,6 +12,8 @@ describe('speed', function () {
let boss

beforeEach(async function () {
const { default: pMap } = await import('p-map')

const defaults = { noSupervisor: true, min: 10, max: 10 }
boss = await helper.start({ ...this.currentTest.bossConfig, ...defaults })
await pMap(jobs, job => boss.send(job.name, job.data))
Expand Down
2 changes: 2 additions & 0 deletions test/testHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function getConfig (options = {}) {
if (inTravis) {
config.password = ''
config.schema = process.env.TRAVIS_JOB_ID
config.user = process.env.PGUSER
config.port = process.env.PGPORT
}

if (options.testKey) {
Expand Down

0 comments on commit c4bcaab

Please sign in to comment.