Skip to content

Commit

Permalink
dropping node 4 from travis and package.json' updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
timgit committed Jul 27, 2018
1 parent a445584 commit d2141aa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -9,7 +9,6 @@ node_js:
- "10"
- "8"
- "6"
- "4"
before_script:
- psql -c 'create database pgboss' -U postgres
script:
Expand Down
43 changes: 15 additions & 28 deletions README.md
Expand Up @@ -7,41 +7,28 @@ Queueing jobs in Node.js using PostgreSQL like a boss.
[![Dependencies](https://david-dm.org/timgit/pg-boss.svg)](https://david-dm.org/timgit/pg-boss)

```js
const PgBoss = require('pg-boss');
const boss = new PgBoss('postgres://user:pass@host/database');
async function readme() {
const PgBoss = require('pg-boss');
const boss = new PgBoss('postgres://user:pass@host/database');

boss.on('error', error => console.error(error));
boss.on('error', error => console.error(error));

boss.start()
.then(ready)
.catch(error => console.error(error));
await boss.start();

const queue = 'some-queue';

function ready() {
const someQueue = 'some-queue';
let jobId = await boss.publish(queue, {param1: 'parameter1'})

console.log(`created job in queue ${queue}: ${jobId}`);

boss.publish(someQueue, {param1: 'parameter1'})
.then(jobId => {
console.log(`created job in queue ${someQueue}: ${jobId}`);
});

boss.subscribe(someQueue, job => someAsyncJobHandler(job))
.then(() => console.log(`subscribed to queue ${someQueue}`));

boss.onComplete(someQueue, job => {
if(job.data.failed)
return console.error(`job ${job.data.request.id} ${job.data.state}`);

console.log(`job ${job.data.request.id} completed`);
console.log(` - responded with '${job.data.response.value}'`);
})
.then(() => console.log(`subscribed to queue ${someQueue} completions`));
await boss.subscribe(queue, someAsyncJobHandler);
}

function someAsyncJobHandler(job) {
console.log(`job ${job.id} received`);
console.log(` - with data: ${JSON.stringify(job.data)}`);
async function someAsyncJobHandler(job) {
console.log(`job ${job.id} received with data:`);
console.log(JSON.stringify(job.data));

return Promise.resolve('got it');
await doSomethingAsyncWithThis(job.data);
}
```

Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,10 +1,10 @@
{
"name": "pg-boss",
"version": "3.0.0-beta7",
"version": "3.0.0-beta8",
"description": "Queueing jobs in Node.js using PostgreSQL like a boss",
"main": "./lib/index.js",
"engines": {
"node": ">=4.0.0",
"node": ">=6.0.0",
"npm": ">=5.0.0"
},
"dependencies": {
Expand Down

0 comments on commit d2141aa

Please sign in to comment.