qboss-lib
v1.0.6
Published
- responsible to generate jobs for qboss project. It wraps some metadata around payload to help qboss-client and -server - can optionally pull jobs and messages from sqs down - onces pulled a message, it can delete this message
Downloads
6
Readme
qboss library
- responsible to generate jobs for qboss project. It wraps some metadata around payload to help qboss-client and -server
- can optionally pull jobs and messages from sqs down
- onces pulled a message, it can delete this message
installation
npm i --save qboss-lib
API
Create an instance
var q = new qboss({ folder: '/tmp', sqs })
depending on use case you might either define folder or sqs or both as options. if you want to pull, you need to instantiate a sqs object by using aws-sdk
Create Jobs
.compose
: will only return a string as a job
.submit
: will create a job inside folder
directory which then will be picken up from qboss-client
Pull and Manage Jobs
.pull(QueueUrl) <Promise>
: will pull a message form sqs and return a job object
Job Object
.delete() <Promise>
: will delete the job from sqs
.getJob()
: will only return the job part of the qboss message
.getMessage()
: will return sqs message body
.getRaw()
: development related
create jobs
var qboss = require('qboss-lib')
// init to create jobs
var q = new qboss({ folder: '/tmp/'})
var payload = {
name:'john',
lastname:'doe',
type:'newperson'
}
// just output to console
console.log(q.compose('test.fifo','secret',payload))
// create a job inside /tmp
q.submit('test.fifo','secret',payload)
pulling jobs
var AWS = require('aws-sdk')
AWS.config.update({region: 'us-east-1'})
var sqs = new AWS.SQS({apiVersion: '2012-11-05',accessKeyId:"OR7R474F42F84FFFASPP",secretAccessKey:"0f7a54e0-e673-46f1-8846-c98f4b288b3a"});
// instantiate
var q = new qboss({
sqs
})
// pull
q.pull('https://sqs.us-east-2.amazonaws.com/593153579764/test.fifo').then(async function (job) {
console.log(job.getJob())
// process
....
// delete
await job.delete()
}).catch(err=>{
console.log(err)
})
structure or created job
{
"version": 1,
"token": "secret",
"libversion": "1.0.2",
"t": 1558340983844,
"id": "2ca6a173-7a58-4d24-8860-acb8d0225c90",
"hostname": "Mac-Pro.local",
"qname": "test.fifo",
"payload": {
"name": "john",
"lastname": "doe",
"type": "newperson"
}
}