bree is a free, open source orchestration & scheduling project written in JavaScript and released under MIT. It has 3,293 GitHub stars, 87 forks and 29 open issues, and was last pushed 7 months ago. On this registry it ranks #37 of 64 tracked projects in Orchestration & Scheduling, with 5 head-to-head comparisons available.

What is bree?

What it is

Bree is Node.js and JavaScript job task scheduler. It runs scheduled work inside Node.js apps. It uses worker threads to spawn sandboxed processes. It supports cron, Date, ms, later, and human-friendly syntax. It lives in Node.js scheduling ecosystem.

Bree solves problem of running recurring and delayed jobs in Node.js without separate queue system. It lets apps define jobs as scripts or objects, then run them on boot, timeout, interval, or cron. It validates interval, timeout, Date, and cron values. It also gives control for retries, throttling, concurrency, cancelable jobs, graceful shutdown, and graceful reloading.

Key capabilities

  • Runs jobs in Node.js worker threads as sandboxed processes.
  • Schedules with cron expressions, Date values, ms durations, later syntax, and human-friendly time representations.
  • Supports async/await jobs, callbacks, done, and completion states.
  • Provides retries, throttling, concurrency, cancelable jobs, graceful shutdown, and graceful reloading.
  • Loads jobs from root jobs directory, or from job objects with name, path, timeout, and interval.
  • Offers instance options, job options, event listening, custom error/message handling, custom worker options, and plugins.
  • Recommends persistent database queries for job state, without forcing Redis or MongoDB.

Who uses it and how

  • Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.
  • Node.js apps place scripts in jobs directory and pass job names or objects to Bree instance.
  • Apps can disable root directory with root: false, or omit path and let Bree combine root and name.
  • Apps run welcome-email style jobs that check database column such as welcome_email_sent_at before sending.
  • Apps use events, custom error handling, retries, and graceful shutdown for long-running or complex jobs.

Getting started

Install with npm install bree or yarn add bree; it works in Node v12.17.0+. Create jobs directory in app root, or pass job objects with name, path, timeout, and interval to new Bree instance.

When to use it — and when not to

Use Bree when you need scheduling inside Node.js and do not want forced Redis or MongoDB job-state layer. Do not use it when you need built-in job-state storage; README says it does not force Redis or MongoDB, and you must query persistent database and manage boolean job states yourself. Also note Bree v9.0.0 has several breaking changes, and v6.5.0 is last version to support Node v10 and browsers.

project readme (upstream, from github) — read inline

bree

build status code style styled with prettier made with lass license npm downloads


Bree is the best job scheduler for Node.js and JavaScript with cron, dates, ms, later, and human-friendly support.


Works in Node v12.17.0+, uses worker threads (Node.js) to spawn sandboxed processes, and supports async/await, retries, throttling, concurrency, and cancelable jobs with graceful shutdown. Simple, fast, and lightweight. Made for Forward Email and Lad.

Table of Contents

Foreword

Bree was created to give you fine-grained control with simplicity, and has built-in support for workers, sandboxed processes, graceful reloading, cron jobs, dates, human-friendly time representations, and much more.

We recommend you to query a persistent database in your jobs, to prevent specific operations from running more than once.

Bree does not force you to use an additional database layer of [Redis][] or [MongoDB][] to manage job state.

In doing so, you should manage boolean job states yourself using queries. For instance, if you have to send a welcome email to users, only send a welcome email to users that do not have a Date value set yet for welcome_email_sent_at.

Install

[npm][]:

npm install bree

[yarn][]:

yarn add bree

Upgrading

To see details about upgrading from the last major version, please see UPGRADING.md.

IMPORTANT: Bree v9.0.0 has several breaking changes, please see UPGRADING.md for more insight.

NOTE: Bree v6.5.0 is the last version to support Node v10 and browsers.

Usage and Examples

The example below assumes that you have a directory jobs in the root of the directory from which you run this example. For example, if the example below is at /path/to/script.js, then /path/to/jobs/ must also exist as a directory. If you wish to disable this feature, then pass root: false as an option.

Inside this jobs directory are individual scripts which are run using [Workers][] per optional timeouts, and additionally, an optional interval or cron expression. The example below contains comments, which help to clarify how this works.

The option jobs passed to a new instance of Bree (as shown below) is an Array. It contains values which can either be a String (name of a job in the jobs directory, which is run on boot) OR it can be an Object with name, path, timeout, and interval properties. If you do not supply a path, then the path is created using the root directory (defaults to jobs) in combination with the name. If you do not supply values for timeout and/nor interval, then these values are defaulted to 0 (which is the default for both, see index.js for more insight into configurable default options).

We have also documented all Instance Options and Job Options in this README below. Be sure to read those sections so you have a complete understanding of how Bree works.

ECMAScript modules (ESM)

// app.mjs

import Bree from 'bree';

const bree = new Bree({
  // ... (see below) ...
});

// top-level await supported in Node v14.8+
await bree.start();

// ... (see below) ...

Please reference the #CommonJS example below for more insight and options.

CommonJS (CJS)

// app.js

const path = require('path');

// optional
const ms = require('ms');
const dayjs = require('dayjs');
const Graceful = require('@ladjs/graceful');
const Cabin = require('cabin');

// required
const Bree = require('bree');

//
// NOTE: see the "Instance Options" section below in this README
// for the complete list of options and their defaults
//
const bree = new Bree({
  //
  // NOTE: by default the `logger` is set to `console`
  // however we recommend you to use CabinJS as it
  // will automatically add application and worker metadata
  // to your log output, and also masks sensitive data for you
  // 
  //
  // NOTE: You can also pass `false` as `logger: false` to disable logging
  //
  logger: new Cabin(),

  //
  // NOTE: instead of passing this Array as an option
  // you can create a `./jobs/index.js` file, exporting
  // this exact same array as `module.exports = [ ... ]`
  // doing so will allow you to keep your job configuration and the jobs
  // themselves all in the same folder and very organized
  //
  // See the "Job Options" section below in this README
  // for the complete list of job options and configurations
  //
  jobs: [
    // runs `./jobs/foo.js` on start
    'foo',

    // runs `./jobs/foo-bar.js` on start
    {
      name: 'foo-bar'
    },

    // runs `./jobs/some-other-path.js` on start
    {
      name: 'beep',
      path: path.join(__dirname, 'jobs', 'some-other-path')
    },

    // runs `./jobs/worker-1.js` on the last day of the month
    {
      name: 'worker-1',
      interval: 'on the last day of the month'
    },

    // runs `./jobs/worker-2.js` every other day
    {
      name: 'worker-2',
      interval: 'every 2 days'
    },

    // runs `./jobs/worker-3.js` at 10:15am and 5:15pm every day except on Tuesday
    {
      name: 'worker-3',
      interval: 'at 10:15 am also at 5:15pm except on Tuesday'
    },

    // runs `./jobs/worker-4.js` at 10:15am every weekday
    {
      name: 'worker-4',
      cron: '15 10 ? * *',
      cronValidate: {
        override: {
          useBlankDay: true
        }
      }
    },

    // runs `./jobs/worker-5.js` on after 10 minutes have elapsed
    {
      name: 'worker-5',
      timeout: '10m'
    },

    // runs `./jobs/worker

readme truncated — read the full docs on github

Frequently asked questions

Is bree free to use?

bree is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does bree do?

Bree is a Node.js and JavaScript job task scheduler with worker threads, cron, Date, and human syntax. Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.

What is bree written in?

bree is primarily written in JavaScript. Its source is publicly available at https://github.com/breejs/bree, and it has 3,293 GitHub stars.