feat: add cron cheatsheet.

This commit is contained in:
jaywcjlove
2022-09-26 22:14:52 +08:00
parent 697d00f277
commit 089b1eaf39
8 changed files with 226 additions and 72 deletions

104
docs/cron.md Normal file
View File

@ -0,0 +1,104 @@
Cron 备忘清单
===
[Cron](https://en.wikipedia.org/wiki/Cron) 最适合安排重复性任务。 可以使用关联的 at 实用程序来完成一次性任务的调度。
Crontab 格式
------
<!--rehype:body-class=cols-2-->
### 格式
```
Min Hour Day Mon Weekday
分钟 小时 天 月 周
```
-------
```
* * * * * 要执行的命令
┬ ┬ ┬ ┬ ┬
│ │ │ │ └─ 星期几 (0=周日 .. 6=星期六)
│ │ │ └────── 月 (1..12)
│ │ └─────────── 月份中的某天 (1..31)
│ └──────────────── 小时 (0..23)
└───────────────────── 分钟 (0..59)
```
------
| 字段 | 范围 | 特殊字符 |
|--------------|--------|--------------------|
| 分钟 Minute | 0 - 59 | , - * / |
| 小时 Hour | 0 - 23 | , - * / |
| 月份中的某天 | 1 - 31 | , - * ? / L W |
| 月 Month | 1 - 12 | , - * / |
| 星期几 | 0 - 6 | , - * ? / L # |
### 示例
| Example | Description |
|----------------|------------------------|
| `*/15 * * * *` | 每 15 分钟 |
| `0 * * * *` | 每隔一小时 |
| `0 */2 * * *` | 每 2 小时 |
| `15 2 * * *` | 每天凌晨 2 点 15 分 |
| `15 2 * * ?` | 每天凌晨 2 点 15 分 |
| `10 9 * * 5` | 每周五上午 9:10 |
| `0 0 * * 0` | 每个星期日的午夜 |
| `15 2 * * 1L` | 每月最后一个星期一凌晨 2 点 15 分 |
| `15 0 * * 4#2` | 每个月的第二个星期四早上 00:15 |
| `0 0 0 1 * *` | 每个月的 1 日(每月) |
| `0 0 0 1 1 *` | 每年 1 月 1 日(每年) |
| `@reboot` | 每次重启 _(非标准)_ |
<!--rehype:class=table-thead-hide-->
### 特殊字符串
| 特殊字符串 | 意义 |
|----------------|----------------------------------------------------|
| @reboot | 运行一次,在系统启动时 _非标准_ |
| @yearly | 每年运行一次“0 0 1 1 *” _非标准_ |
| @annually | (与@yearly 相同_非标准_ |
| @monthly | 每月运行一次“0 0 1 * *_非标准_ |
| @weekly | 每周运行一次“0 0 * * 0” _非标准_ |
| @daily | 每天运行一次“0 0 * * *” _非标准_ |
| @midnight | (与@daily 相同_非标准_ |
| @hourly | 每小时运行一次“0 * * * *_非标准_ |
### Crontab 命令
| - | - |
|--------------|---------------------------------------------|
| `crontab -e` | 如果不存在,则编辑或创建一个 crontab 文件。 |
| `crontab -l` | 显示 crontab 文件。 |
| `crontab -r` | 删除 crontab 文件。 |
| `crontab -v` | 显示您上次编辑 crontab 文件的时间。 _非标准_ |
<!--rehype:class=table-thead-hide-->
### 特殊字符
<!--rehype:warp-class=col-span-2-->
<!--rehype:-->
| 特殊字符 | 说明 |
|---------------------|------------------------------------------------------------------------------------------|
| `Asterik(*)` | 匹配字段中的所有值或任何可能的值。 |
| `Hyphen(-)` | 用于定义范围。例如:第 5 个字段(星期几)中的 1-5 每个工作日,即星期一到星期五 |
| `Slash (/)` | 第一个字段(分钟)/15 表示每十五分钟或范围的增量。 |
| `Comma (,)` | 用于分隔项目。例如:第二个字段(小时)中的 2、6、8 在凌晨 2 点、早上 6 点和早上 8 点执行 |
| `L` | 仅允许用于 `月份中的某天``星期几` 字段,`星期几` 中的 `2L` 表示每个月的最后一个星期二 |
| `Hash (#)` | 仅允许用于 `星期几` 字段,后面必须在 1 到 5 的范围内。例如,`4#1` 表示给定月份的“第一个星期四”。 |
| `Question mark (?)` | 可以代替“*”并允许用于月份和星期几。使用仅限于 cron 表达式中的 `月份中的某天``星期几`。 |
## Also see
* [Devhints](https://devhints.io/cron) _(devhints.io)_
* [Crontab Generator](https://crontab-generator.org/) _(crontab-generator.org)_
* [Crontab guru](https://crontab.guru/) _(crontab.guru)_

View File

@ -1053,7 +1053,7 @@ module.exports = {
}
```
### Require Module
### 加载模块
```javascript
// main.js
@ -1068,7 +1068,7 @@ JavaScript Promises
----
<!--rehype:data-body-style=grid-template-columns: repeat(2,minmax(0,1fr));-->
### Promise states
### Promise 状态
<!--rehype:data-warp-style=grid-row: span 2/span 2;-->
<!--rehype:-->
@ -1086,7 +1086,7 @@ const promise = new Promise((resolve, reject) => {
promise.then((res) => console.log(res), (err) => console.error(err));
```
### Executor function
### 执行器函数
```javascript
const executorFn = (resolve, reject) => {
@ -1104,7 +1104,7 @@ const loginAlert = () =>{
setTimeout(loginAlert, 6000);
```
### .then() method
### .then() 方法
```javascript
const promise = new Promise((resolve, reject) => {
@ -1119,7 +1119,7 @@ promise.then((res) => {
});
```
### .catch() method
### .catch() 方法
```javascript
const promise = new Promise((resolve, reject) => {
@ -1154,7 +1154,7 @@ Promise.all([promise1, promise2]).then((res) => {
});
```
### Avoiding nested Promise and .then()
### 避免嵌套的 Promise .then()
```javascript
const promise = new Promise((resolve, reject) => {
@ -1171,11 +1171,11 @@ const oneDot = (star) => {
const print = (val) => {
console.log(val);
};
// Chaining them all together
// 将它们链接在一起
promise.then(twoStars).then(oneDot).then(print);
```
### Creating
### 创建
```javascript
const executorFn = (resolve, reject) => {
@ -1184,7 +1184,7 @@ const executorFn = (resolve, reject) => {
const promise = new Promise(executorFn);
```
### Chaining multiple .then()
### 链接多个 .then()
```javascript
const promise = new Promise(resolve => setTimeout(() => resolve('dAlan'), 100));
@ -1201,7 +1201,7 @@ JavaScript Async-Await
----
<!--rehype:data-body-style=grid-template-columns: repeat(2,minmax(0,1fr));-->
### Asynchronous
### 异步
```javascript
function helloWorld() {
@ -1211,19 +1211,19 @@ function helloWorld() {
}, 2000);
});
}
const msg = async function() { //Async Function Expression
const msg = async function() { // 异步函数表达式
const msg = await helloWorld();
console.log('Message:', msg);
}
const msg1 = async () => { //Async Arrow Function
const msg1 = async () => { // 异步箭头函数
const msg = await helloWorld();
console.log('Message:', msg);
}
msg(); // Message: Hello World! <-- after 2 seconds
msg1(); // Message: Hello World! <-- after 2 seconds
msg(); // Message: Hello World! <-- 2 秒后
msg1(); // Message: Hello World! <-- 2 秒后
```
### Resolving Promises
### 解决 Promises
```javascript
let pro1 = Promise.resolve(5);
@ -1237,7 +1237,7 @@ Promise.all([pro1, pro2, pro3]).then(function(values) {
// expected => Array [5, 44, "foo"]
```
### Async Await Promises
### 异步等待 Promises
```javascript
function helloWorld() {
@ -1251,22 +1251,22 @@ async function msg() {
const msg = await helloWorld();
console.log('Message:', msg);
}
msg(); // Message: Hello World! <-- after 2 seconds
msg(); // Message: Hello World! <-- 2 秒后
```
### Error Handling
### 错误处理
```javascript
let json = '{ "age": 30 }'; // incomplete data
let json = '{ "age": 30 }'; // 数据不完整
try {
let user = JSON.parse(json); // <-- no errors
let user = JSON.parse(json); // <-- 没有错误
console.log( user.name ); // no name!
} catch (e) {
console.error( "Invalid JSON data!" );
}
```
### Aysnc await operator
### 异步等待运算符
```javascript
function helloWorld() {
@ -1280,7 +1280,7 @@ async function msg() {
const msg = await helloWorld();
console.log('Message:', msg);
}
msg(); // Message: Hello World! <-- after 2 seconds
msg(); // Message: Hello World! <-- 2 秒后
```
JavaScript 请求
@ -1402,7 +1402,7 @@ fetch('https://api-xxx.com/endpoint', {
})
```
### async await syntax
### async await 语法
<!--rehype:data-warp-style=grid-column: span 2/span 2;-->
<!--rehype:-->