Skip to content

Commit

Permalink
added manual ops functions and existence tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timgit committed Dec 20, 2019
1 parent fb43c46 commit f377cab
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@ class Db extends EventEmitter {
constructor (config) {
super()

this.config = config

if (config.poolSize) { config.max = config.poolSize }
if (config.poolSize) {
config.max = config.poolSize
}

config.application_name = config.application_name || 'pgboss'

this.pool = new pg.Pool(config)
this.config = config

this.open()
}

async open () {
this.pool = new pg.Pool(this.config)
this.pool.on('error', error => this.emit('error', error))
this.opened = true
}

async close () {
if (!this.pool.ending) {
await this.pool.end()
this.opened = false
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PgBoss extends EventEmitter {

const boss = new Boss(db, config)
Object.keys(boss.events).forEach(event => promoteEvent.call(this, boss, boss.events[event]))
// boss.functions.forEach(func => promoteFunction.call(this, boss, func))
boss.functions.forEach(func => promoteFunction.call(this, boss, func))

this.config = config
this.db = db
Expand Down Expand Up @@ -75,6 +75,10 @@ class PgBoss extends EventEmitter {

this.isStarted = true

if (this.db.isOurs && !this.db.opened) {
this.db.open()
}

await this.contractor.start()

this.isReady = true
Expand Down Expand Up @@ -102,6 +106,10 @@ class PgBoss extends EventEmitter {
}

async connect () {
if (this.db.isOurs && !this.db.opened) {
this.db.open()
}

await this.contractor.connect()
this.isReady = true
return this
Expand Down
27 changes: 27 additions & 0 deletions test/opsTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const helper = require('./testHelper')

describe('ops', function () {
this.timeout(10000)

let boss

before(async () => {
boss = await helper.start()
await boss.stop()
})

it('should expire manually', async function () {
await boss.connect()
await boss.expire()
})

it('should archive manually', async function () {
await boss.connect()
await boss.archive()
})

it('should purge the archive manually', async function () {
await boss.connect()
await boss.purge()
})
})

0 comments on commit f377cab

Please sign in to comment.