taskloop 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe54ad9d9bfec60de30dcda7607bae029880697f8e3300f3d8f5ca720d1e3b61
4
- data.tar.gz: 1963fb584f8fbb3fdde0d72008a19a3c8568c0b4fe3dc5939a3df22360370cee
3
+ metadata.gz: 83ec59acf2460d59fa1f95974b90e3a5944dd41deb44a17969f82d283c475f39
4
+ data.tar.gz: f6e98ab37a5933243b2b3c8275c4295553aa83da0bb41e971ee9c4515c1d4f50
5
5
  SHA512:
6
- metadata.gz: 534de276e8ced9600bbecc3f7a07a4de578d3addee053ddcacacad7b284e9e59b40f9bde0cd309a2075e0f5ff3692f8c2fc38a9ff08ccedabfae933c792d5e52
7
- data.tar.gz: 529cdbe0ea94872d8960fba3a1b7eba0520d5bd2b0d09ae5f1319c698b20fc63c9d6acb957c0f239e0958e58f0f908531c26caed504956b6c4ae73eaf70f51e4
6
+ metadata.gz: 24074e16853283c1a33d9ccc177ef5dd13ae3202f14e09e735699ce8f02b29c499c3c00e0aec78416ae2521d79922896bc7f75fcc29d4af20e817b5dffefe60f
7
+ data.tar.gz: 9e5ca8fce4a681a12f2d7d91cef006932bd62daf6319186a30c1885c133997f67df38a6d370b9ed6693003f42ff9f283b1bfa621ce4628cbbdc2d2e2563dd1e3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- taskloop (0.2.0)
4
+ taskloop (0.3.0)
5
5
  claide (~> 1.0.3)
6
6
 
7
7
  GEM
data/README-cn.md ADDED
@@ -0,0 +1,273 @@
1
+ ![](https://chuquan-public-r-001.oss-cn-shanghai.aliyuncs.com/sketch-images/taskloop-logo-white.png?x-oss-process=image/resize,w_800)
2
+
3
+ [![Platforms](https://img.shields.io/badge/Platforms-macOS_Linux-yellowgreen)](https://img.shields.io/badge/Platforms-macOS_Linux-Green)
4
+ [![License](https://img.shields.io/badge/License-MIT-orange)](https://img.shields.io/badge/License-MIT-orange)
5
+ [![Gem](https://img.shields.io/badge/Gem-0.3.0-blue)](https://img.shields.io/badge/Gem-0.3.0-blue)
6
+
7
+ [English](https://github.com/baochuquan/taskloop/README.md)
8
+
9
+ Taskloop 是一款基于 crontab 进行了优化的定时任务管理器。
10
+
11
+ 与 crontab 相比,taskloop 提供了更加语义化的语法规则。除了支持 crontab 语法之外,taskloop 还实现了一些扩展,比如循环次数、开始/结束时间、日志查询、环境
12
+ 变量导入等。
13
+
14
+ # Features
15
+
16
+ - [x] 环境变量导入/删除/查看
17
+ - [x] 任务日志查询,taskloop 日志查询
18
+ - [x] 任务发布/撤销
19
+ - [x] 全局开关支持 taskloop 启动/关闭
20
+ - [x] 语义化的语法规则
21
+ - [x] time specific rule
22
+ - [x] time scope rules
23
+ - [x] before scope rule
24
+ - [x] between scope rule
25
+ - [x] after scope rule
26
+ - [x] time interval rule
27
+ - [x] loop count rule
28
+ - [x] execution boundary rules
29
+ - [x] start point boundary rule
30
+ - [x] end point boundary rule
31
+ - [x] date list rule
32
+ - [x] time list rule
33
+
34
+ # Installation
35
+
36
+ 安装 gem 并通过执行以下命令将其添加到应用程序的 Gemfile 中:
37
+
38
+ $ bundle add taskloop
39
+
40
+ 如果没有使用 bundler 来管理依赖项,请通过执行以下命令安装 gem:
41
+
42
+ $ gem install taskloop
43
+
44
+ # Usage
45
+ Taskloop 提供了一系列工作流命令,以及一组语法规则供用户自定义任务。
46
+
47
+ 在使用 taskloop 时,我们建议你使用 git 项目或本地目录来管理所有定时任务。这并不意味着你必须将任务管理集中在一个地方。你可以使用多个 git
48
+ 项目或目录来管理不同类型的定时任务。Taskloop 支持这些不同的管理方式。这些只是建议而已。
49
+
50
+ 接下来介绍一下 taskloop 的标准工作流程。
51
+
52
+ ## 启动
53
+ 在开始使用 taskloop 之前,您需要执行 `taskloop launch` 命令来全局启动 taskloop。
54
+
55
+ 相应的,taskloop 也提供了一个 `taskloop shutdown` 命令来支持全局关闭 taskloop。
56
+
57
+ ## 初始化 Taskfile
58
+ Taskfile 用于描述自定义任务,一个 Taskfile 中可以描述多个任务。因此,我们可以在目录下执行 `taskloop init` 命令来生成 Taskfile,并在
59
+ Taskfile 中描述具体的定时任务。
60
+
61
+ ## 自定义定时任务
62
+ 执行 `taskloop init` 命令后,会在当前目录下自动生成一个 Taskfile 模板文件。模板文件展示了如何描述任务,包括为每个任务指定哪些属性、哪些属性是
63
+ 必需的、哪些属性是可选的。
64
+
65
+ 如下所示是 Taskfile 模板文件:
66
+ ```shell
67
+ # env to set environment variables which are shared by all tasks defined in the Taskfile. <Optional>
68
+ # env "ENV_NAME", "ENV_VALUE"
69
+
70
+ TaskLoop::Task.new do |t|
71
+ t.name = 'TODO: task name. <Required>'
72
+ t.path = 'TODO: task job path. For example, t.path = "./Job.sh". <Required>'
73
+ t.week = 'TODO: week rule. <Optional>'
74
+ t.year = "TODO: year rule. <Optional>"
75
+ t.month = "TODO: month rule. <Optional>"
76
+ t.day = "TODO: day rule. <Optional>"
77
+ t.hour = "TODO: hour rule. <Optional>"
78
+ t.minute = "TODO: minute rule. <Optional>"
79
+ t.date = "TODO: date list rule. <Optional>"
80
+ t.time = "TODO: time list rule. <Optional>"
81
+ t.loop = "TODO: loop count. <Optional>"
82
+ t.start_point = "TODO: start point boundary rule. <Optional>"
83
+ t.end_point = "TODO: end point boundary rule. <Optional>"
84
+ end
85
+ ```
86
+
87
+ 在文件的开头,我们可以使用 `env` 语法为 Taskfile 中的任务定义环境变量。
88
+
89
+ `env` 语法有两个参数,第一个是环境变量的名称,第二个是环境变量的值。我们可以多次使用 `env` 语法来定义多个环境变量。这些环境变量可以被 Taskfile
90
+ 中的所有任务共享。
91
+
92
+ ```shell
93
+ env <ENV_NAME1> <ENV_VALUE1>
94
+ env <ENV_NAME2> <ENV_VALUE2>
95
+ env <ENV_NAME3> <ENV_VALUE3>
96
+ ...
97
+ ```
98
+
99
+ 每个任务都需要使用 `TaskLoop::Task.new` 语法进行初始化,并在 `do` 闭包中设置属性。任务有两个必需属性,`name` 和 `path`,其余属性是可选属
100
+ 性。如果未设置任何可选属性,那么任务将每分钟执行一次。
101
+
102
+ 关于可选属性,有些属性支持多种规则,但不同时支持多个规则。如果在任务描述中多次设置某个属性,则最后一次设置将覆盖之前的所有设置。
103
+
104
+ `week` 属性支持两种规则:`ScopeRule` 和 `SpecificRule`。设置 `week` 属性时,必须使用 taskloop 预定义的符号,如:`:Sun` 表示星期天。
105
+ 这些符号的具体定义可以查看 `lib/taskloop/task/task_property.rb` 中 `WEEK` 的定义。
106
+
107
+ `year` 属性支持三种规则:`ScopeRule`、`SpecificRule` 和 `IntervalRule`。设置 `year` 属性时,可以直接使用数字来表示年份或间隔年数。关于
108
+ 年份属性,taskloop 中没有预定义的符号。
109
+
110
+ `month` 属性支持三种规则:`ScopeRule`、`SpecificRule` 和 `IntervalRule`。定义 `month` 属性时,必须使用预定义的月份符号来设置
111
+ `ScopeRule` 和 `SpecificRule`,例如:`:Aug` 表示八月。 对于 `IntervalRule`,直接使用数字即可,用于表示间隔的月数。这些符号的具体定义可以
112
+ 查看 `lib/taskloop/task/task_property.rb` 中 `MONTH` 的定义。
113
+
114
+ `day` 属性支持三种规则:`ScopeRule`、`SpecificRule` 和 `IntervalRule`。其表示月份中的第几天,taskloop 为其预定义了符号,如:`:day7`
115
+ 表示某月的第 7 天,依此类推。对于这些符号的具体定义,可以查看 `lib/taskloop/task/task_property.rb` 中 `DAY` 的定义。
116
+
117
+ `hour` 属性支持三种规则:`ScopeRule`、`SpecificRule` 和 `IntervalRule`。当你设置 `hour` 属性时,你可以直接使用数字来表示小时值或间隔小
118
+ 时数。
119
+
120
+ `minute` 属性支持三种规则:`ScopeRule`、`SpecificRule` 和 `IntervalRule`。当你设置 `minute` 属性时,你可以直接使用数字来表示分钟值或间
121
+ 隔分钟数。
122
+
123
+ `date` 属性也用于设置日期。当你对 `year`、`month` 和 `day` 属性使用 `SpecificRule` 时,请不要同时设置 `date` 属性。当你为 `year`、
124
+ `month` 和 `day` 属性设置 `SpecificRule` 时, 只能设置一个日期,但是当你使用 `date` 属性时,你可以设置一系列日期。这种可以设置一系列日期的
125
+ 规则在任务循环中称为 `DateListRule`。在使用 `DateListRule` 时,可以传入一系列代表日期的字符,例如:“2023-8-1”。
126
+
127
+ `time` 属性也用于设置时间。当你对 `hour` 和 `minute` 属性使用 `SpecificRule` 时,请不要同时设置 `time` 属性。当你为 `hour` 和
128
+ `minute` 属性设置 `SpecificRule` 时,只能设置一个时间,但是当你使用 `time` 属性时,你可以设置一个时间列表。这种可以设置时间列表的规则在
129
+ taskloop 中被称为 `TimeListRule`。使用 `TimeListRule` 时,可以传入一系列代表时间的字符,例如:“10:00:00”。
130
+
131
+ `loop` 属性用于指示定时任务的执行次数,其唯一支持的规则为 `LoopRule`。使用 `LoopRule` 时,只需要传入一个表示执行次数的数字即可。
132
+
133
+ `start_point` 属性用于指示任务最早执行时间,它支持的规则是为 `StartPointBoundaryRule`。使用 `StartPointBoundaryRule` 时,需要传入表示
134
+ 开始时间的字符串,如:“2023-10-1 10:00:00”。
135
+
136
+ `end_point` 属性用于指示任务的最后执行时间,它支持的规则称为 `EndPointBoundaryRule`。使用 `EndPointBoundaryRule` 时,需要传入表示结束
137
+ 时间的字符串,如:“2023-10-30 10:00:00”。
138
+
139
+ ## Deploy
140
+ 在定义或修改 Taskfile 后,你可以执行 `taskloop deploy` 命令进行部署。部署成功后,taskloop 才会真正按照你定义的规则去执行定时任务。
141
+
142
+ 如果部署 Taskfile 后发现问题,可以重新编辑并再次部署。或者也可以直接通过 `taskloop undeploy` 命令取消部署,从而避免造成严重后果。
143
+
144
+ # Advanced Usage
145
+ ## 环境变量
146
+ 关于环境变量,Taskfile 支持定义本地环境变量。此外,taskloop 还提供 `taskloop env` 命令来支持导入/删除/查看环境变量。例如:
147
+
148
+ ```shell
149
+ # to list all the global environment variables
150
+ $ taskloop env
151
+
152
+ # to import PATH and RUBY_HOME
153
+ $ taskloop env --import=PATH,RUBY_HOME
154
+
155
+ # to remove MY_HOME environment variable
156
+ $ taskloop env --remove=MY_HOME
157
+ ```
158
+
159
+ ## 任务列表
160
+ 如果我们想查看 taskloop 中正在运行哪些计划任务,这时候我们可以使用 `taskloop list` 命令。如下所示:
161
+
162
+ ```shell
163
+ $ taskloop list
164
+ ```
165
+
166
+ ## 日志查询
167
+ 如果我们想查询任务的执行日志,可以使用 `taskloop log` 命令,它支持查看特定任务的日志和系统的日志。如下所示:
168
+
169
+ ```shell
170
+ # to query the log of task which is named "morning tip"
171
+ $ taskloop log --task-name="morning tip"
172
+
173
+ # to query the system log of taskloop
174
+ $ taskloop log --cron
175
+ ```
176
+
177
+ # Rules
178
+ 通过上文,我们知道任务的不同属性对应着不同的规则。接下来介绍一下这些规则的具体用法。
179
+
180
+ ## IntervalRule
181
+ 如果你想每隔一段时间执行一个任务,你需要使用 `IntervalRule`。支持 `IntervalRule` 的属性包括 `year`、`month`、`day`、`hour`、`minute`。
182
+ 当你在不同的属性上使用 `IntervalRule` 时,它们的单位是不同的,最终 taskloop 会组合计算出它们执行任务的时间间隔。
183
+
184
+ `IntervalRule` 的语法是 `interval`,`IntervalRule` 的使用示例如下所示。
185
+
186
+ ```ruby
187
+ # execute the task every 5 minutes
188
+ t.minute = interval 5
189
+
190
+ # execute the task every 1 hour and 10 minutes
191
+ t.hour = interval 1
192
+ t.minute = interval 5
193
+ ```
194
+
195
+ ## ScopeRule
196
+ 如果你想指定在某个时间范围内执行的任务,那么你可以使用 `ScopeRule`。事实上,`ScopeRule` 包含三种特定类型的规则,分别是 `BeforeScopeRule`、
197
+ `BetweenScopeRule`、`AfterScopeRule`。支持 `ScopeRule` 的属性包括 `week`、`year`、`month`、`day`、`hour`、`min`。以下是
198
+ `ScopeRule` 用法的一些示例。
199
+
200
+ ```ruby
201
+ # executed between 10 o'clock and 19 o'clock
202
+ t.hour = between 10, 19
203
+
204
+ # execute before 30 minutes of the hour
205
+ t.minute = before 30
206
+
207
+ # executed after october
208
+ t.month = after :Oct
209
+
210
+ # execute within working days
211
+ t.week = between :Mon, :Fri
212
+ ```
213
+
214
+ ## SpecificRule
215
+ 如果你想指定某个时间单位来执行,那么你可以使用 `SpecificRule`。其使用 `at` 语法。支持 `SpecificRule` 的属性包括 `week`、`year`、`month`、
216
+ `day`、`hour`、`min`。以下是 `SpecificRule` 用法的一些示例。
217
+
218
+ ```ruby
219
+ # execute at 10 o'clock
220
+ t.hour = at 10
221
+ t.minute = at 0
222
+ ```
223
+
224
+ ## DateListRule
225
+ 如果要指定一个或多个日期来执行任务,可以使用 `DateListRule`,它使用 `date` 语法。仅 `date` 属性支持 `DateListRule`。以下是 `DateListRule`
226
+ 的示例。
227
+
228
+ ```ruby
229
+ # execute at 2023-10-1, 2023-10-15, 2023-10-30
230
+ t.date = date "2023-10-1", "2023-10-15", "2023-10-30"
231
+ ```
232
+
233
+ ## TimeListRule
234
+ 如果要指定执行一次或多次任务,可以使用 `TimeListRule`,它使用 `time` 语法。只有 `time` 属性支持 `TimeListRule`。以下是 `TimeListRule`
235
+ 的示例。
236
+
237
+ ```ruby
238
+ # execute at 10:00:00, 11:00:00, 12:00:00
239
+ t.time = time "10:00:00", "11:00:00", "12:00:00"
240
+ ```
241
+
242
+ ## LoopRule
243
+ 如果你想控制任务的执行次数,可以使用 `LoopRule`,它使用 `loop` 语法。只有 `loop` 属性支持 `LoopRule`。以下是 `LoopRule` 的示例。
244
+
245
+ ```ruby
246
+ # only execute 5 times
247
+ t.loop = loop 5
248
+ ```
249
+
250
+ ## StartPointBoundaryRule
251
+ 如果你希望任务在特性时间之后开始执行,那么你可以使用 `StartPointBoundaryRule`,它使用 `from` 语法。仅 `start_point` 属性支持
252
+ `StartPointBoundaryRule`。以下是 `StartPointBoundaryRule` 的示例。
253
+
254
+ ```ruby
255
+ # the task will start from 2023-10-1 10:00:00 at the earliest
256
+ t.start_point = from "2023-10-1: 10:00:00"
257
+ ```
258
+
259
+ ## EndPointBoundaryRule
260
+ 如果你希望任务在特定时间后停止执行,那么你可以使用 `EndPointBoundaryRule`,它使用 `to` 语法。仅 `end_point` 属性支持 `EndPointBoundaryRule`。
261
+ 以下是 `EndPointBoundaryRule` 的示例。
262
+
263
+ ```ruby
264
+ # the task will end after 2023-10-1 10:00:00
265
+ t.end_point = to "2023-10-1: 10:00:00"
266
+ ```
267
+
268
+ # Contributing
269
+ 欢迎在 GitHub 上提交 issue 和 PR:https://github.com/baochuquan/taskloop。
270
+
271
+ # License
272
+ Taskloop 在 MIT 许可证下发布。
273
+
data/README.md CHANGED
@@ -1,12 +1,38 @@
1
- ![](https://chuquan-public-r-001.oss-cn-shanghai.aliyuncs.com/sketch-images/taskloop-logo-white.png)
1
+ ![](https://chuquan-public-r-001.oss-cn-shanghai.aliyuncs.com/sketch-images/taskloop-logo-white.png?x-oss-process=image/resize,w_800)
2
2
 
3
- # Taskloop
3
+ [![Platforms](https://img.shields.io/badge/Platforms-macOS_Linux-yellowgreen)](https://img.shields.io/badge/Platforms-macOS_Linux-Green)
4
+ [![License](https://img.shields.io/badge/License-MIT-orange)](https://img.shields.io/badge/License-MIT-orange)
5
+ [![Gem](https://img.shields.io/badge/Gem-0.3.0-blue)](https://img.shields.io/badge/Gem-0.3.0-blue)
4
6
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/taskloop`. To experiment with that code, run `bin/console` for an interactive prompt.
7
+ [简体中文](https://github.com/baochuquan/taskloop/blob/main/README-cn.md)
6
8
 
7
- TODO: Delete this and the text above, and describe your gem
9
+ Taskloop is a scheduled task manager optimized based on crontab.
8
10
 
9
- ## Installation
11
+ Compared to crontab, taskloop offers more user-friendly and semantic syntax rules. In addition to supporting crontab
12
+ syntax, taskloop also provides some extensions, such as the number of loops, start/end time, log query, environment
13
+ variable import, etc.
14
+
15
+ # Features
16
+
17
+ - [x] Environment variable import/remove/list
18
+ - [x] Task log query, taskloop log query
19
+ - [x] Task deploy/undeploy
20
+ - [x] Global switch to enable/disable taskloop
21
+ - [x] user-friendly and semantic syntax rules
22
+ - [x] time specific rule
23
+ - [x] time scope rules
24
+ - [x] before scope rule
25
+ - [x] between scope rule
26
+ - [x] after scope rule
27
+ - [x] time interval rule
28
+ - [x] loop count rule
29
+ - [x] execution boundary rules
30
+ - [x] start point boundary rule
31
+ - [x] end point boundary rule
32
+ - [x] date list rule
33
+ - [x] time list rule
34
+
35
+ # Installation
10
36
 
11
37
  Install the gem and add to the application's Gemfile by executing:
12
38
 
@@ -16,16 +42,261 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
42
 
17
43
  $ gem install taskloop
18
44
 
19
- ## Usage
45
+ # Usage
46
+ TaskLoop provides a series of commands for workflows, as well as a set of syntax rules for users to customize their tasks.
47
+
48
+ When using taskloop, we recommend that you use a git project or a local directory to manage all your scheduled tasks.
49
+ This doesn't mean that you have to centralize management in just one place; of course, you can use multiple git
50
+ projects or directories to manage different types of scheduled tasks. Taskloop supports these different management
51
+ methods; these are just recommendations.
52
+
53
+ Next, let's introduce the standard workflow of Taskloop.
54
+
55
+ ## Launch
56
+ Before you start using taskloop, you need to execute the `taskloop launch` command to globally launch taskloop.
57
+
58
+ Correspondingly, taskloop also provides a `taskloop shutdown` command to globally shutdown taskloop.
59
+
60
+ ## Init Taskfile
61
+ A Taskfile is used to describe custom tasks, and multiple tasks can be described in one Taskfile. Therefore, we can
62
+ execute the `taskloop init` command in a directory to generate a Taskfile and describe specific tasks in the Taskfile.
63
+
64
+ ## Customize Scheduled Task
65
+ After you execute the `taskloop init` command, a Taskfile template file will be automatically generated in the current
66
+ directory. The template file describes how to describe a task, including which attributes are specified
67
+ for each task, which attributes are required, and which attributes are optional.
68
+
69
+ The following is the Taskfile template file:
70
+ ```shell
71
+ # env to set environment variables which are shared by all tasks defined in the Taskfile. <Optional>
72
+ # env "ENV_NAME", "ENV_VALUE"
73
+
74
+ TaskLoop::Task.new do |t|
75
+ t.name = 'TODO: task name. <Required>'
76
+ t.path = 'TODO: task job path. For example, t.path = "./Job.sh". <Required>'
77
+ t.week = 'TODO: week rule. <Optional>'
78
+ t.year = "TODO: year rule. <Optional>"
79
+ t.month = "TODO: month rule. <Optional>"
80
+ t.day = "TODO: day rule. <Optional>"
81
+ t.hour = "TODO: hour rule. <Optional>"
82
+ t.minute = "TODO: minute rule. <Optional>"
83
+ t.date = "TODO: date list rule. <Optional>"
84
+ t.time = "TODO: time list rule. <Optional>"
85
+ t.loop = "TODO: loop count. <Optional>"
86
+ t.start_point = "TODO: start point boundary rule. <Optional>"
87
+ t.end_point = "TODO: end point boundary rule. <Optional>"
88
+ end
89
+ ```
90
+
91
+ At the beginning of the file, we can define environment variables for the tasks in the Taskfile, using the `env` syntax.
92
+
93
+ The env syntax takes two arguments, the first is the name of the environment variable and the second is the value of the
94
+ environment variable. We can use the env syntax multiple times to define multiple environment variables. These environment
95
+ variables are shared by all tasks in the Taskfile.
96
+
97
+ ```shell
98
+ env <ENV_NAME1> <ENV_VALUE1>
99
+ env <ENV_NAME2> <ENV_VALUE2>
100
+ env <ENV_NAME3> <ENV_VALUE3>
101
+ ...
102
+ ```
103
+
104
+ Every task needs to be initialized using the `TaskLoop::Task.new` syntax, and set the property in the `do` closure.
105
+ There are two required attributes of a task, `name` and `path`, and the rest are optional attributes. If none of the
106
+ optional properties is set, the task will be executed every minute.
107
+
108
+ Regarding optional attributes, some attributes support multiple rules, but do not support rules at the same time. If a
109
+ property is set multiple times in a task description, the last setting will override all previous settings.
110
+
111
+ The `week` attribute implements two rules: `ScopeRule` and `SpecificRule`. When you set the week attribute, you must use
112
+ the symbols defined by taskloop, such as: `:Sun` means Sunday. For the specific definition of these symbols, you can
113
+ check the definition of `WEEK` in `lib/taskloop/task/task_property.rb`.
114
+
115
+ The `year` attribute implements three rules: `ScopeRule`, `SpecificRule` and `IntervalRule`. When you set the `year`
116
+ property, you can directly use numbers to represent the year or interval. Regarding the year attribute, there is no
117
+ predefined symbols for taskloop.
118
+
119
+ The `month` attribute implements three rules: `ScopeRule`, `SpecificRule` and `IntervalRule`. When defining the `month`
120
+ property, you have to set `ScopeRule` and `SpecificRule` with predefined month symbols, such as: `:Aug` means August.
121
+ For `IntervalRule`, just use a number directly, which is used to represent the number of months in the interval. For the
122
+ specific definition of these symbols, you can check the definition of `MONTH` in `lib/taskloop/task/task_property.rb`.
123
+
124
+ The `day` attribute implements three rules: `ScopeRule`, `SpecificRule` and `IntervalRule`. It indicates the day of the
125
+ month,taskloop has predefined symbols for it, such as: `:day7` means the 7th day of a certain month, and so on. For the
126
+ specific definition of these symbols, you can check the definition of `DAY` in `lib/taskloop/task/task_property.rb`.
127
+
128
+ The `hour` attribute implements three rules: `ScopeRule`, `SpecificRule` and `IntervalRule`. When you set the `hour`
129
+ property, you can directly use numbers to represent hour value or interval.
130
+
131
+ The `minute` attribute implements three rules: `ScopeRule`, `SpecificRule` and `IntervalRule`. When you set the `minute`
132
+ property, you can directly use numbers to represent minute value or interval.
133
+
134
+ The `date` attribute is also used to set the date. When you use `SpecificRule` for `year`, `month` and `day` property,
135
+ please don't set `date` property at the same time. When you set `SpecificRule` for `year`, `month` and `day` attribute,
136
+ you can only set one date, but when you use `date` attribute, you can set a list of dates. This kind of rule that can
137
+ set a series of dates is called `DateListRule` in taskloop. When using `DateListRule`, you can pass in a series of
138
+ characters representing the date, for example: "2023-8-1".
139
+
140
+ The `time` attribute is also used to set the time. When you use `SpecificRule` for `hour` and `minute` property, please
141
+ don't set `time` property at the same time. When you set `SpecificRule` for `hour` and `minute` attribute, you can only
142
+ set one time, but when you use `time` attribute, you can set a time list. This kind of rule that can set a time list is
143
+ called `TimeListRule` in taskloop. When using `TimeListRule`, you can pass in a series of characters representing the
144
+ time, for example: "10:00:00".
145
+
146
+ The `loop` attribute is used to indicate the execution times of the scheduled task, and the only supported rule is
147
+ called `LoopRule`. When using `LoopRule`, you only need to pass in a number indicating the number of executions.
148
+
149
+ The `start_point` attribute is used to indicate the earliest execution time of the task, and the rule it supports is
150
+ called `StartPointBoundaryRule`. When using `StartPointBoundaryRule`, you need to pass in a string representing the
151
+ start time, such as: "2023-10-1 10:00:00".
152
+
153
+ The `end_point` attribute is used to indicate the last execution time of the task, and the rule it supports is called
154
+ `EndPointBoundaryRule`. When using `EndPointBoundaryRule`, you need to pass in a string representing the end time, such
155
+ as: "2023-10-30 10:00:00".
156
+
157
+ ## Deploy
158
+ After you define or modify the Taskfile, you can execute the `taskloop deploy` command to deploy. After the deployment
159
+ is successful, the taskloop will actually execute the scheduled tasks according to the rules you defined.
160
+
161
+ If you find a problem after deploying the Taskfile, you can re-edit it and deploy it again. Or you can undeploy it
162
+ directly through the `taskloop undeploy` command to avoid serious consequences.
163
+
164
+ # Advanced Usage
165
+ ## Environment Variable
166
+ Regarding environment variables, Taskfile supports defining local environment variables. In addition, taskloop also
167
+ provides a `taskloop env` command to support importing/deleting/viewing environment variables. For example:
168
+
169
+ ```shell
170
+ # to list all the global environment variables
171
+ $ taskloop env
172
+
173
+ # to import PATH and RUBY_HOME
174
+ $ taskloop env --import=PATH,RUBY_HOME
175
+
176
+ # to remove MY_HOME environment variable
177
+ $ taskloop env --remove=MY_HOME
178
+ ```
179
+
180
+ ## List Task
181
+ If we want to see which scheduled tasks are running in the taskloop, we can use the taskloop list command at this time.
182
+ For example:
183
+
184
+ ```shell
185
+ $ taskloop list
186
+ ```
187
+
188
+ ## Log Query
189
+ If we want to query the execution log of the task, we can use the `taskloop log` command, which supports the log of
190
+ specific tasks and the log of the system. For example:
191
+
192
+ ```shell
193
+ # to query the log of task which is named "morning tip"
194
+ $ taskloop log --task-name="morning tip"
195
+
196
+ # to query the system log of taskloop
197
+ $ taskloop log --cron
198
+ ```
199
+
200
+ # Rules
201
+ In above, we know that different attributes of tasks refer to different rules. Next, let's introduce the specific usage
202
+ of these rules.
203
+
204
+ ## IntervalRule
205
+ If you want to execute a task every period of time, you need to use `IntervalRule`. Attributes that support
206
+ `IntervalRule` include `year`, `month`, `day`, `hour`, `minute`. When you use `IntervalRule` on different properties, their units are
207
+ different, and finally taskloop will calculate the time interval of their combination to execute the task.
208
+
209
+ The syntax of `IntervalRule` is `interval`, and the usage example of `IntervalRule` is shown below.
210
+
211
+ ```ruby
212
+ # execute the task every 5 minutes
213
+ t.minute = interval 5
214
+
215
+ # execute the task every 1 hour and 10 minutes
216
+ t.hour = interval 1
217
+ t.minute = interval 5
218
+ ```
219
+
220
+ ## ScopeRule
221
+ If you want to specify the task to execute within a time range, then you can use `ScopeRule`. In fact, `ScopeRule`
222
+ contains three specific types of rules, which are `BeforeScopeRule`, `BetweenScopeRule`, `AfterScopeRule`. Attributes
223
+ that support `ScopeRule` include `week`, `year`, `month`, `day`, `hour`, `minute`. Here are a few examples of
224
+ `ScopeRule` usage.
225
+
226
+ ```ruby
227
+ # executed between 10 o'clock and 19 o'clock
228
+ t.hour = between 10, 19
229
+
230
+ # execute before 30 minutes of the hour
231
+ t.minute = before 30
232
+
233
+ # executed after october
234
+ t.month = after :Oct
235
+
236
+ # execute within working days
237
+ t.week = between :Mon, :Fri
238
+ ```
239
+
240
+ ## SpecificRule
241
+ If you want to specify a certain time unit to execute, then you can use `SpecificRule`. which uses `at`
242
+ syntax. Attributes that support `SpecificRule` include `week`, `year`, `month`, `day`, `hour`, `minute`. Here are a few
243
+ examples of `SpecificRule` usage.
244
+
245
+ ```ruby
246
+ # execute at 10 o'clock
247
+ t.hour = at 10
248
+ t.minute = at 0
249
+ ```
250
+
251
+ ## DateListRule
252
+ If you want to specify one or more dates to execute the task, you can use `DateListRule`, which uses `date` syntax. Only
253
+ `date` attribute support `DateListRule`. Here is an example of `DateListRule`.
254
+
255
+ ```ruby
256
+ # execute at 2023-10-1, 2023-10-15, 2023-10-30
257
+ t.date = date "2023-10-1", "2023-10-15", "2023-10-30"
258
+ ```
259
+
260
+ ## TimeListRule
261
+ If you want to specify one or more times to execute the task, you can use `TimeListRule`, which uses `time` syntax. Only
262
+ `time` attribute support `TimeListRule`. Here is an example of `TimeListRule`.
263
+
264
+ ```ruby
265
+ # execute at 10:00:00, 11:00:00, 12:00:00
266
+ t.time = time "10:00:00", "11:00:00", "12:00:00"
267
+ ```
268
+
269
+ ## LoopRule
270
+ If you want to control the number of executions of tasks, you can use `LoopRule`, which uses `loop` syntax. Only `loop` attribute support
271
+ `LoopRule`. Here is an example of `LoopRule`.
272
+
273
+ ```ruby
274
+ # only execute 5 times
275
+ t.loop = loop 5
276
+ ```
277
+
278
+ ## StartPointBoundaryRule
279
+ If you want to set the earliest time when the task will be executed for the first time, then you can use
280
+ `StartPointBoundaryRule`, which uses `from` syntax. Only `start_point` attribute support `StartPointBoundaryRule`. Here
281
+ is an example of `StartPointBoundaryRule`.
20
282
 
21
- TODO: Write usage instructions here
283
+ ```ruby
284
+ # the task will start from 2023-10-1 10:00:00 at the earliest
285
+ t.start_point = from "2023-10-1: 10:00:00"
286
+ ```
22
287
 
23
- ## Development
288
+ ## EndPointBoundaryRule
289
+ If you want to prevent tasks from executing after a certain time, then you can use `EndPointBoundaryRule`, which uses
290
+ `to` syntax. Only `end_point` attribute support `EndPointBoundaryRule`. Here is an example of `EndPointBoundaryRule`.
24
291
 
25
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
292
+ ```ruby
293
+ # the task will end after 2023-10-1 10:00:00
294
+ t.end_point = to "2023-10-1: 10:00:00"
295
+ ```
26
296
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
297
+ # Contributing
298
+ Bug reports and pull requests are welcome on GitHub at https://github.com/baochuquan/taskloop.
28
299
 
29
- ## Contributing
300
+ # License
301
+ Taskloop is released under the MIT license.
30
302
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/taskloop.
@@ -6,7 +6,7 @@ module TaskLoop
6
6
 
7
7
  self.description = <<-DESC
8
8
  The `taskloop env` command can be used to deal with global environment variable related operations.
9
- For example, you can export environment variables into taskloop with `--global-export=VAR1,VAR2...` options.
9
+ For example, you can export environment variables into taskloop with `--import=VAR1,VAR2...` options.
10
10
  Beside, you can list all the global environment variables exported in taskloop.
11
11
  All above operations are based on ~/.taskloop/environments file. If you want more details about global environment
12
12
  variables, check and edit ~/.taskloop/environments by yourself.
@@ -14,14 +14,14 @@ module TaskLoop
14
14
 
15
15
  def self.options
16
16
  [
17
- ['--global-import=VAR1,VAR2...', 'Import one or more global environment variables into taskloop.'],
18
- ["--global-remove=VAR1,VAR2...", 'Remove one or more global environment variables from taskloop.']
17
+ ['--import=VAR1,VAR2...', 'Import one or more global environment variables into taskloop.'],
18
+ ["--remove=VAR1,VAR2...", 'Remove one or more global environment variables from taskloop.']
19
19
  ].concat(super)
20
20
  end
21
21
 
22
22
  def initialize(argv)
23
- @import = argv.option('global-import')
24
- @remove = argv.option('global-remove')
23
+ @import = argv.option('import')
24
+ @remove = argv.option('remove')
25
25
  super
26
26
  end
27
27
 
@@ -26,15 +26,18 @@ module TaskLoop
26
26
 
27
27
  TaskLoop::Task.new do |t|
28
28
  t.name = 'TODO: task name. <Required>'
29
- t.path = 'TODO: task job path. For exmaple, t.path = "./Job.sh". <Required>'
29
+ t.path = 'TODO: task job path. For example, t.path = "./Job.sh". <Required>'
30
+ t.week = 'TODO: week rule. <Optional>'
30
31
  t.year = "TODO: year rule. <Optional>"
31
32
  t.month = "TODO: month rule. <Optional>"
32
33
  t.day = "TODO: day rule. <Optional>"
33
34
  t.hour = "TODO: hour rule. <Optional>"
34
35
  t.minute = "TODO: minute rule. <Optional>"
36
+ t.date = "TODO: date list rule. <Optional>"
37
+ t.time = "TODO: time list rule. <Optional>"
35
38
  t.loop = "TODO: loop count. <Optional>"
36
- t.start_point = "TODO: start point boundary rule. <Optional"
37
- t.end_point = "TODO: start point boundary rule. <Optional"
39
+ t.start_point = "TODO: start point boundary rule. <Optional>"
40
+ t.end_point = "TODO: end point boundary rule. <Optional>"
38
41
  end
39
42
  DESC
40
43
  file.puts content
@@ -66,11 +66,13 @@ module TaskLoop
66
66
  when :month then
67
67
  result = current.month >= value
68
68
  when :week then
69
- result = current.wday >= (value % TaskLoop::WEEK_BASE)
69
+ result = current.wday >= value
70
70
  when :day then
71
71
  result = current.day >= value
72
72
  when :hour then
73
73
  result = current.hour >= value
74
+ when :minute then
75
+ result = current.min >= value
74
76
  end
75
77
  return result
76
78
  end
@@ -65,11 +65,13 @@ module TaskLoop
65
65
  when :month then
66
66
  result = current.month <= value
67
67
  when :week then
68
- result = current.wday <= (value % TaskLoop::WEEK_BASE)
68
+ result = current.wday <= value
69
69
  when :day then
70
70
  result = current.day <= value
71
71
  when :hour then
72
72
  result = current.hour <= value
73
+ when :minute then
74
+ result = current.min <= value
73
75
  end
74
76
  return result
75
77
  end
@@ -105,11 +105,13 @@ module TaskLoop
105
105
  when :month then
106
106
  result = left <= current.month && current.month <= right
107
107
  when :week then
108
- result = (left % TaskLoop::WEEK_BASE) <= current.wday && current.wday <= (right % TaskLoop::WEEK_BASE)
108
+ result = left <= current.wday && current.wday <= right
109
109
  when :day then
110
110
  result = left <= current.day && current.day <= right
111
111
  when :hour then
112
112
  result = left <= current.hour && current.hour <= right
113
+ when :minute then
114
+ result = left <= current.min && current.min <= right
113
115
  end
114
116
  return result
115
117
  end
@@ -3,7 +3,7 @@ module TaskLoop
3
3
 
4
4
  UNIT = {
5
5
  :unknown => 0,
6
- :minute => 1, # support interval/specific syntax
6
+ :minute => 1, # support interval/scope/specific syntax
7
7
  :hour => 2, # support interval/scope/specific syntax
8
8
  :day => 3, # support interval/scope/specific syntax
9
9
  :month => 4, # support interval/scope/specific syntax
@@ -39,7 +39,7 @@ module TaskLoop
39
39
  when :month then
40
40
  result = vals.include?(current.month)
41
41
  when :week then
42
- result = vals.include?(TaskLoop::WEEK_BASE + current.wday)
42
+ result = vals.include?(current.wday)
43
43
  when :day then
44
44
  result = vals.include?(current.day)
45
45
  when :hour then
@@ -98,10 +98,7 @@ module TaskLoop
98
98
  break
99
99
  end
100
100
  end
101
-
102
101
  end
103
-
104
-
105
102
  end
106
103
 
107
104
  if has_ymd? && has_time?
@@ -222,9 +222,16 @@ module TaskLoop
222
222
  # interval syntax
223
223
  # - interval
224
224
  # - example: interval 5.minute
225
+ # scope syntax
226
+ # - before
227
+ # - example: before 9
228
+ # - between
229
+ # - example: between 10, 12
230
+ # - after
231
+ # - example: after 11
225
232
  def minute=(rule)
226
- unless rule.is_a?(SpecificRule) || rule.is_a?(IntervalRule)
227
- raise TypeError, "the rule of minute must be SpecificRule or IntervalRule"
233
+ unless rule.is_a?(SpecificRule) || rule.is_a?(ScopeRule) || rule.is_a?(IntervalRule)
234
+ raise TypeError, "the rule of minute must be SpecificRule or ScopeRule or IntervalRule"
228
235
  end
229
236
  @minute = rule
230
237
  @minute.unit = :minute
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TaskLoop
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -56,9 +56,9 @@ module TaskLoop
56
56
 
57
57
  def loop_count: () -> Integer
58
58
 
59
- def minute: () -> [SpecificRule | IntervalRule]
59
+ def minute: () -> [SpecificRule | ScopeRule | IntervalRule]
60
60
 
61
- def minute=: ([SpecificRule | IntervalRule]) -> void
61
+ def minute=: ([SpecificRule | ScopeRule | IntervalRule]) -> void
62
62
 
63
63
  def month: () -> [SpecificRule | ScopeRule | IntervalRule | DefaultRule]
64
64
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taskloop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - baochuquan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-31 00:00:00.000000000 Z
11
+ date: 2023-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide
@@ -39,6 +39,7 @@ files:
39
39
  - ".idea/vcs.xml"
40
40
  - Gemfile
41
41
  - Gemfile.lock
42
+ - README-cn.md
42
43
  - README.md
43
44
  - Rakefile
44
45
  - exe/taskloop