Skip to content

Commit

Permalink
Merge 7dbaf88 into b091ca1
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jul 28, 2021
2 parents b091ca1 + 7dbaf88 commit dc54b2c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,29 @@ yarn add pg-boss
## Documentation
* [Usage](docs/usage.md)
* [Configuration](docs/configuration.md)

## Contributing

To setup a development environment for this library:

```bash
git clone https://github.com/timgit/pg-boss.git
npm install

```

To run the test suite you will need to pgboss access to an empty postgres database. You can set one up using the following commands on a local postgres instance:

```sql
CREATE DATABASE pgboss;
CREATE user postgres WITH PASSWORD 'postgres';
GRANT ALL PRIVILEGES ON DATABASE pgboss to postgres;
```

If you use a different database name, username or password, or want to run the test suite against a database that is running on a remote machine then you will need to edit the `test/config.json` file with the appropriate connection values.

You can then run the linter and test suite using:

```bash
npm run test
```
6 changes: 5 additions & 1 deletion src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ class Manager extends EventEmitter {
mapCompletionDataArg (data) {
if (data === null || typeof data === 'undefined' || typeof data === 'function') { return null }

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

return (typeof data === 'object' && !Array.isArray(data))
? data
Expand Down
17 changes: 17 additions & 0 deletions test/failureTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ describe('failure', function () {
assert.strictEqual(job.data.response.someReason, failPayload.someReason)
})

it('should preserve nested objects within a payload that is an instance of Error', async function () {
const boss = this.test.boss = await helper.start(this.test.bossConfig)

const queue = 'fail-payload'
const failPayload = new Error('Something went wrong')
failPayload.some = { deeply: { nested: { reason: 'nuna' } } }

const jobId = await boss.publish(queue, null, { onComplete: true })

await boss.fail(jobId, failPayload)

const job = await boss.fetchCompleted(queue)

assert.strictEqual(job.data.state, 'failed')
assert.strictEqual(job.data.response.some.deeply.nested.reason, failPayload.some.deeply.nested.reason)
})

it('subscribe failure via done() should pass error payload to failed job', async function () {
const boss = this.test.boss = await helper.start(this.test.bossConfig)

Expand Down

0 comments on commit dc54b2c

Please sign in to comment.