npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mmstudio/schedule

v4.0.1

Published

Node.js schedule service.

Downloads

35

Readme

1. Node.js Service

1. Description

定时任务,适用于例如“每天的0点”或“每年3,6,9月份的第二个周日”执行的任务,如果是每隔一分钟执行一次的任务,则不适用于这类任务.

2. 服务

根据配置定时调用某个服务,服务调用与普通的服务区别:

  1. 无动态参数,如果需要配置某些固定参数,请在mm.json中的data中配置
  2. 无返回值

3. 注意

正常情况下,服务不可部署多个实例,但若定时任务的系统资源消耗量过大,可以部署多个,但需要修改定时任务的策略,让多个定时任务的服务的工作合并时达到预期值即可。比如定时任务需要执行a,b,c三个任务,而a任务的工作量过大,可以将a单独配置部署,即配置文件mm.jsonjobs中只包含a的任务,b和c合并部署一台服务器。再比如a的定时任务实在太大,同一台服务器资源受限无法完成,可以将a再次拆解,假如a任务每隔10分钟执行一次,可以分解为两个服务实例,单个服务器的执行任务策略修改为20分钟一次。

在正式环境部署时,最好使用docker进行,且设定其在导致异常时重启容器。

4. 开发

yarn dev-schedule

5. 编译

yarn build

6. 运行

yarn build

7. Config

7.1. mm.json

{
	"jobs": [
		{
			"service": "s001",
			"description": "example for schedule",
			"rule": "* * * * * *",
			"start": "",
			"end": "",
			"data": {
				"test": "feidao"
			}
		}
	]
}

7.1.1. service

服务文件名,为项目下 src/schedule下相对文件名。

7.1.2. description

定时任务说明

7.1.3. rule

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    │
│    │    │    │    │    └ 一周中的第几天 (0 - 7) (0 或 7 为周日)
│    │    │    │    └───── 月 (1 - 12)
│    │    │    └────────── 一个月的第几天 (1 - 31)
│    │    └─────────────── 小时 (0 - 23)
│    └──────────────────── 分钟 (0 - 59)
└───────────────────────── 秒 (0 - 59, 非必填)

说明:

  • * 表示全部
  • ? 不详,试验结果在第4项(一个月的第几天)和第6项(一周中的第几天)中与*等效
  • m-n 表示从mn期间都执行
  • */n 表示每隔n个时间单位执行一次
  • m,n 表示mn都执行
  • #m 表示第二个,如* * * * * 0#m表示每个月的第二个周日

7.1.4. start

时间戳或时间字符串,如

1610440541000
"1/12/2021, 4:35:41 PM"
"1/12/2021, 16:35:41"
"1/12/2021"
"Tue Jan 12 2021"
"Tue Jan 12 2021 16:35:41 GMT+0800 (China Standard Time)"
"Tue Jan 12 2021 16:35:41 GMT+0800"

7.1.5. end

1610440541000
"1/12/2021, 4:35:41 PM"
"1/12/2021, 16:35:41"
"1/12/2021"
"Tue Jan 12 2021"
"Tue Jan 12 2021 16:35:41 GMT+0800 (China Standard Time)"
"Tue Jan 12 2021 16:35:41 GMT+0800"

7.1.6. data

附加固定参数,比如第三方服务如微信服务的appid之类的。

7.2. log4js.json

日志配置,具体请参考官方说明:log4js