|
2 | 2 |
|
3 | 3 | This bundle provides multiple type of tasks: |
4 | 4 |
|
5 | | -- [ShellTask](tasks.md#ShellTask) |
6 | | -- [CommandTask](tasks.md#CommandTask) |
7 | | -- [ChainedTask](tasks.md#ChainedTask) |
8 | | -- [CallbackTask](tasks.md#CallbackTask) |
| 5 | +- [ShellTask](#ShellTask) |
| 6 | +- [CommandTask](#CommandTask) |
| 7 | +- [ChainedTask](#ChainedTask) |
| 8 | +- [CallbackTask](#CallbackTask) |
9 | 9 | - HttpTask |
10 | 10 | - MessengerTask |
11 | | -- [NotificationTask](tasks.md#NotificationTask) |
12 | | -- [NullTask](tasks.md#NullTask) |
| 11 | +- [NotificationTask](#NotificationTask) |
| 12 | +- [NullTask](#NullTask) |
13 | 13 |
|
14 | 14 | ## Extra |
15 | 15 |
|
16 | | -- [Task callbacks](tasks.md#Callbacks) |
17 | | -- [Task notifications](tasks.md#Notifications) |
18 | | -- [Options](tasks.md#Options) |
| 16 | +- [Task callbacks](#Callbacks) |
| 17 | +- [Task notifications](#Notifications) |
| 18 | +- [Options](#Options) |
| 19 | +- [Fluent Expression](#fluent-expressions) |
19 | 20 |
|
20 | 21 | ## ShellTask |
21 | 22 |
|
@@ -180,3 +181,73 @@ Each task can define a set of notification: |
180 | 181 | ## Options |
181 | 182 |
|
182 | 183 | Each task has its own set of options, the full list is documented in [AbstractTask](../src/Task/AbstractTask.php). |
| 184 | + |
| 185 | +## Fluent expressions |
| 186 | + |
| 187 | +_Introduced in `0.3`_ |
| 188 | + |
| 189 | +This bundle supports defining tasks expression via basic cron syntax: |
| 190 | + |
| 191 | +```bash |
| 192 | +* * * * * |
| 193 | +``` |
| 194 | + |
| 195 | +Even if this approach is mostly recommended, you may need to use a more "user-friendly" syntax, to do so, |
| 196 | +this bundle allows you to use "fluent" expressions thanks to [strtotime](https://www.php.net/manual/fr/function.strtotime) and "computed" expressions: |
| 197 | + |
| 198 | +### Strtotime |
| 199 | + |
| 200 | +Scheduling a task with a "fluent" expression is as easy as it sounds: |
| 201 | + |
| 202 | +```yaml |
| 203 | +scheduler_bundle: |
| 204 | + # ... |
| 205 | + tasks: |
| 206 | + foo: |
| 207 | + type: 'shell' |
| 208 | + command: ['ls', '-al'] |
| 209 | + expression: 'next monday 10:00' |
| 210 | +``` |
| 211 | +
|
| 212 | +Every expression supported by [strtotime](https://www.php.net/manual/fr/function.strtotime) is allowed. |
| 213 | +
|
| 214 | +_Note: Keep in mind that using a fluent expression does not lock the amount of execution of the task, |
| 215 | +if it should only run once, you must consider using the `single_run` option._ |
| 216 | + |
| 217 | +_Note: If you need to generate the expression thanks to a specific timezone, the `timezone` option can be used:_ |
| 218 | + |
| 219 | +```yaml |
| 220 | +scheduler_bundle: |
| 221 | + # ... |
| 222 | + tasks: |
| 223 | + foo: |
| 224 | + type: 'shell' |
| 225 | + command: ['ls', '-al'] |
| 226 | + expression: 'next monday 10:00' |
| 227 | + timezone: 'Europe/Paris' |
| 228 | +``` |
| 229 | + |
| 230 | +*The default value is `UTC`* |
| 231 | + |
| 232 | +### Computed expressions |
| 233 | + |
| 234 | +A "computed" expression is a special expression that use `#` for specific parts of the expression: |
| 235 | + |
| 236 | +```yaml |
| 237 | +scheduler_bundle: |
| 238 | + # ... |
| 239 | + tasks: |
| 240 | + foo: |
| 241 | + type: 'shell' |
| 242 | + command: ['ls', '-al'] |
| 243 | + expression: '# * * * *' |
| 244 | +``` |
| 245 | + |
| 246 | +The final expression will contain an integer 0 and 59 in the minute field of the expression |
| 247 | +as described in the [man page](https://crontab.guru/crontab.5.html). |
| 248 | + |
| 249 | +_Note: `#` can be used in multiple parts of the expression at the same time._ |
| 250 | + |
| 251 | +### Notices |
| 252 | + |
| 253 | +Both computed and fluent expressions cannot be used *outside* of the configuration definition. |
0 commit comments