1.0.1 • Published 5 years ago

bid.js v1.0.1

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

Bid.js

In-memory work queue

How to

Install

npm i bid.js

Import

import Bid from 'bid.js'

Use

// Creating new instances of our queue
const bid = new Bid();

// Set up a process callback
bid.setProcess((job, progress, done) => {
  // ..Logic
  const result = 'The job is done!';
  done(null, result);
});

// Add your first payload for queue
bid.add({some: "payload"});
/*
By the way this payload appears in job.payload
*/

API

new Bid( config )

optiondefaultwhat for
config.enumeratefalseEnumerate job.id instead of random id
config.processundefinedCallback function to handle the payload

Bid instance

optionusagewhat for
bid.setProcesscallback(job, progress, done)Set the process callback
bid.addpayloadAdd new payload to queue
bid.on('start', cb(job))Callback event on every job was started
bid.on('finish', cb(job))Callback event on every job was finished
bid.on('error', cb(job))Callback event on job was done with error
bid.on('end', cb())Callback event on queue is ended

Job

optionvaluewhat for
job.idstring/id numberJob unique/serial id
job.name?undefinedJob string name
job.donebooleanIs the job already done without error
job.finishednumberUnixtime job was finished
job.creatednumberUnixtime job was created
job.progressnumberJob workflow progress percent
job.payloadanyJob payload
job.deadbooleanIs job dead (timeout)
job.resultanyJob result with which it was finished ( done(error?, result?) )
job.errorError/stringJob error with which it was finished ( done(error?, result?) )

More helpfull

Also try to use it with typescript, just import Bid with all the types it uses

import Bid from 'bid.js'
import {
  BidProcess,
  BidCallback,
  BidEvent,
  BidStatus,
  BidJob,
  BidProcessJob,
  Done,
  Progress,
  BidConfig,
  BidError,
} from  'bid.js';

Tests

npm run test
1.0.1

5 years ago

1.0.0

5 years ago