timgit / pg-boss

Queueing jobs in Postgres from Node.js like a boss
MIT License
2.13k stars 158 forks source link

Problems with onComplete() documentation (and behavior?) #151

Closed leventov closed 4 years ago

leventov commented 4 years ago

https://github.com/timgit/pg-boss/blob/master/docs/usage.md#oncompletename--options-handler

1) onComplete() handler apparently doesn't make the completion job completed if it just normally exits. The code example in the doc contains a non-existent finished() function call which kind of indicates that: it only works if I replace finished() with boss.complete(job.id)

2) Instead of example

{
    "request": {
        "id": "26a608d0-79bf-11e8-8391-653981c16efd",
        "name": "onCompleteFtw",
        "data": {
            "token": "trivial"
        }
    },
    "response": {
        "message": "so verbose",
        "code": "1234"
    },
    "failed": false,
    "state": "completed",
    "createdOn": "2018-06-26T23:04:12.9392-05:00",
    "startedOn": "2018-06-26T23:04:12.945533-05:00",
    "completedOn": "2018-06-26T23:04:12.949092-05:00",
    "retryCount": 0
}

I think it would be clearer to show that the job passed into handler is actually:

{
    "id": ...
    "name": ...
    "data": {
        "request": {
            "id": "26a608d0-79bf-11e8-8391-653981c16efd",
            "name": "onCompleteFtw",
            "data": {
                "token": "trivial"
            }
        },
        "response": {
            "message": "so verbose",
            "code": "1234"
        },
        "failed": false,
        "state": "completed",
        "createdOn": "2018-06-26T23:04:12.9392-05:00",
        "startedOn": "2018-06-26T23:04:12.945533-05:00",
        "completedOn": "2018-06-26T23:04:12.949092-05:00",
        "retryCount": 0
    }
}
timgit commented 4 years ago

I updated the docs for this. Thanks for the feedback https://github.com/timgit/pg-boss/commit/6f5567edad817660aba9a2eadc3feb29792bcae4v

leventov commented 4 years ago

Thanks. Could you please comment on the need for manual boss.complete(job.id)?

timgit commented 4 years ago

I added an enhancement label to that issue. :+1: