node-cron vs agenda vs bree vs bull vs cron vs later vs node-schedule
Node.js 定时任务库
node-cronagendabreebullcronlaternode-schedule类似的npm包:

Node.js 定时任务库

定时任务库用于在 Node.js 中调度和执行定时任务。这些库提供了不同的功能和灵活性,帮助开发者在特定时间或间隔执行任务。它们适用于需要定期执行的任务,如发送电子邮件、清理数据库、生成报告等。选择合适的库可以提高应用程序的效率和可维护性。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
node-cron3,186,4783,249221 kB349 个月前ISC
agenda09,652295 kB21 个月前MIT
bree03,28492 kB291 个月前MIT
bull016,245309 kB1471 年前MIT
cron08,916161 kB264 个月前MIT
later02,418-9810 年前MIT
node-schedule09,22135 kB1713 年前MIT

功能对比: node-cron vs agenda vs bree vs bull vs cron vs later vs node-schedule

持久化任务

  • node-cron:

    Node-Cron 不支持持久化任务,适合轻量级的定时任务。

  • agenda:

    Agenda 提供了持久化任务的功能,任务信息存储在 MongoDB 中,确保任务在应用重启后仍然存在。适合需要高可靠性的任务调度。

  • bree:

    Bree 不支持持久化任务,任务在内存中执行,适合轻量级和短期任务。

  • bull:

    Bull 支持持久化任务,任务信息存储在 Redis 中,确保任务的可靠性和持久性。

  • cron:

    Cron 不支持持久化任务,适合简单的定时任务,任务信息在内存中。

  • later:

    Later 不支持持久化任务,适合短期任务和简单调度。

  • node-schedule:

    Node-Schedule 不支持持久化任务,适合灵活的调度需求。

调度灵活性

  • node-cron:

    Node-Cron 提供简单的 cron 风格调度,适合小型应用。

  • agenda:

    Agenda 提供了丰富的调度选项,支持重复任务、延迟任务和复杂的调度逻辑,适合复杂的应用场景。

  • bree:

    Bree 提供简单的调度选项,适合快速开发和简单任务。

  • bull:

    Bull 提供了优先级和延迟任务的支持,适合需要处理大量任务的应用。

  • cron:

    Cron 使用类 Unix 的 cron 表达式,适合简单的定时任务。

  • later:

    Later 提供了灵活的调度选项,支持多种时间格式,适合高度自定义的调度需求。

  • node-schedule:

    Node-Schedule 支持 cron 表达式和日期对象,适合多种调度需求。

性能

  • node-cron:

    Node-Cron 性能良好,适合轻量级的定时任务。

  • agenda:

    Agenda 性能依赖于 MongoDB 的性能,适合需要高可靠性的任务调度。

  • bree:

    Bree 使用 worker 线程执行任务,适合 CPU 密集型任务,性能优越。

  • bull:

    Bull 基于 Redis,提供高性能的任务队列,适合处理大量任务。

  • cron:

    Cron 性能良好,适合简单的定时任务。

  • later:

    Later 性能适中,适合短期任务和简单调度。

  • node-schedule:

    Node-Schedule 性能适中,适合灵活的调度需求。

易用性

  • node-cron:

    Node-Cron API 简单,易于使用,适合新手。

  • agenda:

    Agenda 提供了简单的 API,易于上手,适合新手和快速开发。

  • bree:

    Bree API 简洁,易于使用,适合快速开发。

  • bull:

    Bull 提供了丰富的功能,可能需要一定的学习成本,但文档清晰。

  • cron:

    Cron API 简单,易于理解,适合小型项目。

  • later:

    Later API 灵活,适合需要自定义调度的开发者。

  • node-schedule:

    Node-Schedule API 灵活,适合多种调度需求,学习曲线适中。

社区支持

  • node-cron:

    Node-Cron 社区活跃,文档简单,适合新手。

  • agenda:

    Agenda 拥有活跃的社区和良好的文档支持,适合需要社区帮助的开发者。

  • bree:

    Bree 社区相对较小,但文档清晰,适合快速开发。

  • bull:

    Bull 拥有强大的社区支持和丰富的文档,适合需要帮助的开发者。

  • cron:

    Cron 社区活跃,文档简单易懂,适合新手。

  • later:

    Later 社区较小,但文档清晰,适合自定义调度的开发者。

  • node-schedule:

    Node-Schedule 拥有活跃的社区和良好的文档支持,适合需要社区帮助的开发者。

如何选择: node-cron vs agenda vs bree vs bull vs cron vs later vs node-schedule

  • node-cron:

    选择 Node-Cron 如果你需要一个轻量级的 cron 风格的调度库,易于使用且不依赖外部存储。它适合简单的定时任务,适合小型应用。

  • agenda:

    选择 Agenda 如果你需要一个基于 MongoDB 的任务调度库,适合需要持久化任务和复杂调度的场景。它支持重复任务和延迟任务,非常适合需要高可靠性的应用。

  • bree:

    选择 Bree 如果你需要一个轻量级的任务调度库,支持使用 worker 线程来执行任务,适合 CPU 密集型任务。它简单易用,适合快速开发和小型项目。

  • bull:

    选择 Bull 如果你需要一个高性能的任务队列,支持优先级、延迟和重试机制,适合需要处理大量任务的应用。它基于 Redis,提供了强大的功能和良好的性能。

  • cron:

    选择 Cron 如果你需要一个简单的定时任务调度器,支持类 Unix 的 cron 表达式,适合简单的定时任务。它易于使用,适合小型项目和简单的调度需求。

  • later:

    选择 Later 如果你需要一个灵活的定时任务调度库,支持复杂的调度逻辑和多种时间格式。它适合需要高度自定义的调度需求。

  • node-schedule:

    选择 Node-Schedule 如果你需要一个功能丰富的调度库,支持复杂的时间规则和日期,适合需要灵活调度的应用。它支持 cron 表达式和日期对象,适合多种调度需求。

node-cron的README

Node Cron

npm npm NPM Downloads Coverage Status

The node-cron module is tiny task scheduler in pure JavaScript for node.js based on GNU crontab. This module allows you to schedule task in node.js using full crontab syntax.

Node-Cron Documentation

Getting Started

Install node-cron using npm:

npm install --save node-cron

Import node-cron and schedule a task:

  • commonjs
const cron = require('node-cron');

cron.schedule('* * * * *', () => {
  console.log('running a task every minute');
});
  • es6 (module)
import cron from 'node-cron';

cron.schedule('* * * * *', () => {
  console.log('running a task every minute');
});

Cron Syntax

This is a quick reference to cron syntax and also shows the options supported by node-cron.

Allowed fields

 # ┌────────────── second (optional)
 # │ ┌──────────── minute
 # │ │ ┌────────── hour
 # │ │ │ ┌──────── day of month
 # │ │ │ │ ┌────── month
 # │ │ │ │ │ ┌──── day of week
 # │ │ │ │ │ │
 # │ │ │ │ │ │
 # * * * * * *

Allowed values

fieldvalue
second0-59
minute0-59
hour0-23
day of month1-31
month1-12 (or names)
day of week0-7 (or names, 0 or 7 are sunday)

Issues

Feel free to submit issues and enhancement requests here.

Contributing

In general, we follow the "fork-and-pull" Git workflow.

  • Fork the repo on GitHub;
  • Commit changes to a branch in your fork;
  • Pull request "upstream" with your changes;

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

Please do not contribute code you did not write yourself, unless you are certain you have the legal ability to do so. Also ensure all contributed code can be distributed under the ISC License.

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

node-cron is under ISC License.