0.1.0 • Published 1 year ago

@backkit/bee v0.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

bee

Backkit service for beequeue, redis based job queue

install

npm install --save @backkit/bee

configuration example

test:
  queue:
    redis:
      host: 127.0.0.1
      port: 6379
      db: 0
    removeOnSuccess: false
    removeOnFailure: false
    stallInterval: 5000
    nearTermWindow: 60000
    delayedDebounce: 500
  worker:
    concurrency: 50

*note that you can use any configuration available for bee: https://github.com/bee-queue/bee-queue#settings

worker example (async)

res/bee/test.js

module.exports = ({bee}) => bee.worker('test', async (job) => {
  return await true;
});

job producer example

services/bee-job-producer.js

class BeeJobProducerService {
  constructor({bee}) {
    this.bee = bee;
  }
    
  run() {
    setInterval(() => {
      const queue = this.bee.getQueue('test');
      queue
      .ready()
      .then(() => {
        const job = queue.createJob({x: Math.random()*1000, y: Math.random()*1000});
        return job
        .retries(3)
        .timeout(1000*30)
        .on('succeeded', (result) => {
          console.log(`result for job ${job.queue.name}/${job.id}: ${result}`);
        })
        .on('failed', (jor, err) => {
          console.log(`job ${job.queue.name}/${job.id} failed:`, err.message);
        })
        .on('stalled', (jobId) => {
          console.log(`job ${job.queue.name}/${job.id} stalled...`);
        })
        .on('retrying', (jor, err) => {
          console.log(`job ${job.queue.name}/${job.id} failed (${err.message}), retrying...`);
        })
        .save();
      })
      .then((job) => {
        console.log(`job ${job.queue.name}/${job.id} created on ${queue.name} queue`);
      })
      .catch(err => {
        console.log(`error creating job on ${queue.name} queue: ${err.message}`)
      })
    }, 500);
  }
}

module.exports = BeeJobProducerService;