timgit / pg-boss

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

Documentation for fetch is incorrect #69

Closed GuyHadas closed 6 years ago

GuyHadas commented 6 years ago

The job/jobs returned from boss.fetch(name) do not have a done method, but rather it seems (according to the tests) that I must call boss.complete(job.id) to mark the job as completed.

https://github.com/timgit/pg-boss/blob/master/docs/usage.md#fetchname-batchsize

const jobName = 'email-daily-digest';
const batchSize = 20;

boss.fetch(jobName, batchSize)
  .then(jobs => {
    if(!jobs) return;

    console.log(`received ${jobs.length} ${jobName} jobs`);

    // our magical emailer knows what to do with job.data
    let promises = jobs.map(job => emailer.send(job.data).then(() => job.done()));

    return Promise.all(promises);      
  })
  .catch(error => console.log(error));

The above is an example for the fetch documentation in the usage docs, but it incorrectly shows a job being marked as completed with the done function.

While I don't understand why a job that was manually fetched has a different interface as one coming from subscribe, we should at least fix the documentation.

Note, I have a commit locally that fixes the documentation, but don't have proper permissions to push to origin.

timgit commented 6 years ago

Good catch! Thanks. You can always fork and submit a PR, too. I'll leave this issue open until I update it, or maybe you can beat me to it. :)