Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass the error supplied to the done callback on through the fail handler #37

Merged
merged 1 commit into from
Oct 16, 2017

Conversation

ericmittelhammer
Copy link
Contributor

when failing a job by passing an error to job.done, the error is dropped, causing data to be undefined here:

: this.publish(job.name + stateSuffix, {request: job, response: data || null});

example:


const PgBoss = require('pg-boss');
const boss = new PgBoss('postgres://pgbosstest:pgbosstest@localhost/pgbosstest');

boss.on('error', onError);

boss.start()
  .then(ready)
  .catch(onError);

function ready() {

  boss.publish('failed-job', {param1: 'parameter1'})
    .then(jobId => console.log(`created failed-job ${jobId}`))
    .catch(onError);

  boss.subscribe('failed-job', failedJobHandler)
    .then(() => console.log('subscribed to failed-job'))
    .catch(onError);
}

function failedJobHandler(job) {
  console.log(`received ${job.name} ${job.id}`);
  console.log(`data: ${JSON.stringify(job.data)}`);

  job.done('this job failed')
    .then(() => console.log(`failed-job ${job.id} failed`))
    .catch(onError);
}
function onError(error) {
  console.error(error);
}

before/after this commit:

----------------------------------------------------------------------------------------------------------------------------------------------------
id           | a9afb020-af74-11e7-927f-d55cf5669043
name         | failed-job__state__failed
priority     | 0
data         | {"request": {"id": "a9151dd0-af74-11e7-927f-d55cf5669043", "data": {"param1": "parameter1"}, "name": "failed-job"}, "response": null}
state        | created
retrylimit   | 0
retrycount   | 0
startin      | 00:00:00
startedon    |
singletonkey |
singletonon  |
expirein     | 00:15:00
createdon    | 2017-10-12 13:42:05.602788-04
completedon  |
----------------------------------------------------------------------------------------------------------------------------------------------------
id           | 321220a0-af76-11e7-b2d5-f7ed48d6a25c
name         | failed-job__state__failed
priority     | 0
data         | {"request": {"id": "3176f210-af76-11e7-b2d5-f7ed48d6a25c", "data": {"param1": "parameter1"}, "name": "failed-job"}, "response": "this job failed"}
state        | created
retrylimit   | 0
retrycount   | 0
startin      | 00:00:00
startedon    |
singletonkey |
singletonon  |
expirein     | 00:15:00
createdon    | 2017-10-12 13:53:03.914305-04
completedon  |

@coveralls
Copy link

coveralls commented Oct 12, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 9532664 on ericmittelhammer:pass-error-to-fail-handler into 248e212 on timgit:master.

@timgit
Copy link
Owner

timgit commented Oct 16, 2017

👍 Thanks @ericmittelhammer for the PR on this. I'll add a test to make sure this doesn't slip through in the future as well.

@timgit timgit merged commit 1622e1a into timgit:master Oct 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants