Skip to content

Commit

Permalink
update cron.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lily0325 committed Oct 21, 2024
1 parent 23c84e4 commit 896c7ec
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default defineConfig({
items: [
{ text: 'WebSocket', link: '/knowledge/ws' },
{ text: 'SSE', link: '/knowledge/sse' },
{ text: '定时任务', link: '/knowledge/cron' },
],
},
],
Expand Down
3 changes: 2 additions & 1 deletion docs/function/deploy+ssl.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ Congratulations, all renewals succeeded. The following certs have been renewed:

测试自动更新时他是需要80端口空出来的,如果当前nginx还占着80端口记得先把nginx关闭,测试完再重新启动nginx。

或者在nginx配置上开放自动更新的


## 5.重新部署

Expand Down Expand Up @@ -168,4 +170,3 @@ Congratulations, all renewals succeeded. The following certs have been renewed:
重新启动后端

不过后端一般还包括mysql,mysql可以使用sql文件进行导入数据和表

75 changes: 75 additions & 0 deletions docs/knowledge/cron.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 定时任务设定

## 分情况使用

### 1.后端使用

`springboot`自带`@Scheduled`注解,就是用来执行定时任务的,根据传入的cron表达式定时执行添加注解的函数。

### 2.Linux服务器使用

在linux上使用`crontab`来执行定时任务。

查看当前Linux系统中的定时任务
```shell
crontab -l
```

编辑当前Linux系统中的定时任务
```shell
crontab -e
```

一般定时任务设定格式:

`[cron表达式]` + `[用户身份]` + `[执行命令]`

示例:0 0,12 * * * sudo -u root /sbin/hwclock --hctosys(每天0点与12点使用root用户执行系统时间与硬件时间同步任务)

## Cron表达式

cron 表达式是一个字符串,该字符串由 6 个空格分为 7 个域,每一个域代表一个时间含义。 格式如下:

```
[秒] [分] [时] [日] [月] [周] [年]
```
通常定义 “年” 的部分可以省略,实际常用的由 前六部分组成

### Cron 的各个域的定义

|| 是否必填 | 值以及范围 | 通配符 |
| ----------- | ----------- | ----------- | ----------- |
|||0-59 | , - * / |
|||0-59 | , - * / |
|||0-23 | , - * / |
|||1-31 | , - * ? / L W |
|||1-12 或 JAN-DEC | , - * / |
|||1-7 或 SUN-SAT | , - * ? / L # |
|||1970-2099 | , - * / |


数字:表示对应的时间点值(如1表示1点)

星号(*):表示该字段的所有可能值,如分钟字段中的星号表示每分钟的任何时间点

逗号(,):用于分割字段中的多个取值,如“2,5,10”表示取值为2、5、10的时间点

连接符(-):用于指定时间段,如“1-5”表示取值范围为1到5的所有时间点

斜杠(/):用于指定时间步长,如“*/10”表示每隔10个时间点执行一次任务



### 示例

每隔1分钟执行一次:`0 */1 * * * ?`

每天22点执行一次:`0 0 22 * * ?`

每月1号凌晨1点执行一次:`0 0 1 1 * ?`

每月最后一天23点执行一次:`0 0 23 L * ?`

每周周六凌晨3点实行一次:`0 0 3 ? * L`

在24分、30分执行一次:`0 24,30 * * * ?`

0 comments on commit 896c7ec

Please sign in to comment.