Socket
Socket
Sign inDemoInstall

bree

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bree - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

68

index.js

@@ -107,4 +107,5 @@ const { Worker } = require('worker_threads');

new Error(
`Job #${i +
1} "${job}" requires root directory option to auto-populate path`
`Job #${
i + 1
} "${job}" requires root directory option to auto-populate path`
)

@@ -300,40 +301,40 @@ );

getHumanToMs(val) {
val = humanInterval(val);
if (Number.isNaN(val)) val = ms(val);
return val;
getHumanToMs(value) {
value = humanInterval(value);
if (Number.isNaN(value)) value = ms(value);
return value;
}
getTimeout(val) {
if (this.isSchedule(val)) return val;
getTimeout(value) {
if (this.isSchedule(value)) return value;
if (isSANB(val)) {
const schedule = later.schedule(later.parse.text(val));
if (isSANB(value)) {
const schedule = later.schedule(later.parse.text(value));
if (schedule.isValid()) return schedule;
val = this.getHumanToMs(val);
value = this.getHumanToMs(value);
}
if (!Number.isFinite(val) || val < 0)
if (!Number.isFinite(value) || value < 0)
throw new Error(
`Value ${val} must be a finite number >= 0 or a String parseable by \`later.parse.text\` (see <https://bunkat.github.io/later/parsers.html#text> for examples)`
`Value ${value} must be a finite number >= 0 or a String parseable by \`later.parse.text\` (see <https://bunkat.github.io/later/parsers.html#text> for examples)`
);
return val;
return value;
}
getInterval(val) {
if (this.isSchedule(val)) return val;
getInterval(value) {
if (this.isSchedule(value)) return value;
if (isSANB(val)) {
const schedule = later.schedule(later.parse.text(val));
if (isSANB(value)) {
const schedule = later.schedule(later.parse.text(value));
if (schedule.isValid()) return schedule;
val = this.getHumanToMs(val);
value = this.getHumanToMs(value);
}
// will throw error re-using existing logic
return this.getTimeout(val);
return this.getTimeout(value);
}
isSchedule(val) {
return typeof val === 'object' && Array.isArray(val.schedules);
isSchedule(value) {
return typeof value === 'object' && Array.isArray(value.schedules);
}

@@ -344,5 +345,8 @@

if (name) {
const job = this.config.jobs.find(j => j.name === name);
const job = this.config.jobs.find((j) => j.name === name);
if (!job) throw new Error(`Job "${name}" does not exist`);
if (this.workers[name]) throw new Error(`Job "${name}" already running`);
if (this.workers[name])
return this.config.logger.error(
new Error(`Job "${name}" is already running`)
);
debug('starting worker', name);

@@ -370,12 +374,12 @@ this.workers[name] = new Worker(job.path, {

});
this.workers[name].on('message', message => {
this.workers[name].on('message', (message) => {
this.config.logger.info(`${prefix} sent a message`, { message });
});
this.workers[name].on('messageerror', err => {
this.workers[name].on('messageerror', (err) => {
this.config.logger.error(`${prefix} had a message error`, { err });
});
this.workers[name].on('error', err => {
this.workers[name].on('error', (err) => {
this.config.logger.error(`${prefix} had an error`, { err });
});
this.workers[name].on('exit', code => {
this.workers[name].on('exit', (code) => {
delete this.workers[name];

@@ -397,6 +401,8 @@ this.config.logger[code === 0 ? 'info' : 'error'](

if (name) {
const job = this.config.jobs.find(j => j.name === name);
const job = this.config.jobs.find((j) => j.name === name);
if (!job) throw new Error(`Job ${name} does not exist`);
if (this.timeouts[name] || this.intervals[name])
throw new Error(`Job "${name}" is already started`);
return this.config.logger.error(
new Error(`Job "${name}" is already started`)
);

@@ -514,3 +520,3 @@ debug('job', job);

if (this.workers[name]) {
this.workers[name].once('message', message => {
this.workers[name].once('message', (message) => {
if (message === 'cancelled') {

@@ -517,0 +523,0 @@ this.config.logger.info(

{
"name": "bree",
"description": "The best job scheduler for Node.js with support for cron, ms, and human-friendly strings. Uses workers and spawns sandboxed processes. Supports async/await, retries, throttling, concurrency, and cancelable promises (graceful shutdown). Simple, fast, and the most lightweight tool for the job. Made for Lad.",
"version": "0.0.3",
"version": "0.0.4",
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",

@@ -37,3 +37,3 @@ "ava": {

"cross-env": "latest",
"eslint": "6.x",
"eslint": "^7.4.0",
"eslint-config-xo-lass": "latest",

@@ -46,6 +46,6 @@ "fixpack": "latest",

"remark-preset-github": "latest",
"xo": "0.25"
"xo": "^0.32.1"
},
"engines": {
"node": ">= 12"
"node": ">= 12.11.0"
},

@@ -52,0 +52,0 @@ "homepage": "https://github.com/breejs/bree",

@@ -7,3 +7,3 @@ const path = require('path');

test('creates a basic job and runs it', async t => {
test('creates a basic job and runs it', async (t) => {
const bree = new Bree({

@@ -15,3 +15,3 @@ root: path.join(__dirname, 'jobs'),

bree.start();
await new Promise(resolve => setTimeout(resolve, 1));
await new Promise((resolve) => setTimeout(resolve, 1));
t.log(bree);

@@ -21,3 +21,3 @@ t.true(typeof bree.workers.basic === 'object');

bree.workers.basic.on('error', reject);
bree.workers.basic.on('exit', code => {
bree.workers.basic.on('exit', (code) => {
t.true(code === 0);

@@ -24,0 +24,0 @@ resolve();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc