You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `cron.enabled` configuration option should be set to `true` in the `./config/server.js` (or `./config/server.ts` for TypeScript projects) [file](/cms/configurations/server).
6569
-
:::
6570
-
6571
-
`cron` allows scheduling arbitrary functions for execution at specific dates, with optional recurrence rules. These functions are named cron jobs. `cron` only uses a single timer at any given time, rather than reevaluating upcoming jobs every second/minute.
6572
-
6573
-
This feature is powered by the
6574
-
6575
-
</Tabs>
6576
-
6577
-
<details>
6578
-
<summary>Advanced example #1: Timezones</summary>
6579
-
6580
-
The following cron job runs on a specific timezone:
6581
-
6582
-
</Tabs>
6583
-
6584
-
</details>
6585
-
6586
-
<details>
6587
-
<summary>Advanced example #2: One-off cron jobs</summary>
6588
-
The following cron job is run only once at a given time:
6589
-
6590
-
</Tabs>
6591
-
6592
-
</details>
6593
-
6594
-
<details>
6595
-
<summary>Advanced example #3: Start and end times</summary>
6596
-
6597
-
The following cron job uses start and end times:
6598
-
6599
-
</Tabs>
6600
-
6601
-
</details>
6602
-
6603
-
### Using the key format
6604
-
6605
-
:::warning
6606
-
Using the key format creates an anonymous cron job which may cause issues when trying to disable the cron job or with some plugins. It is recommended to use the object format.
6607
-
:::
6608
-
6609
-
To define a cron job with the key format, create a file with the following structure:
6610
-
6611
-
</Tabs>
6612
-
6613
-
## Enabling cron jobs
6614
-
6615
-
To enable cron jobs, set `cron.enabled` to `true` in the [server configuration file](/cms/configurations/server) and declare the jobs:
6616
-
6617
-
</Tabs>
6618
-
6619
-
## Adding or removing cron jobs
6620
-
6621
-
Use `strapi.cron.add` anywhere in your custom code add CRON jobs to the Strapi instance:
Use `strapi.cron.remove` anywhere in your custom code to remove CRON jobs from the Strapi instance, passing in the key corresponding to the CRON job you want to remove:
6642
-
6643
-
```js
6644
-
strapi.cron.remove("myJob");
6645
-
```
6646
-
6647
-
:::note
6648
-
Cron jobs that are using the [key as the rule](/cms/configurations/cron#using-the-key-format) can not be removed.
6649
-
:::
6650
-
6651
-
## Listing cron jobs
6652
-
6653
-
Use `strapi.cron.jobs` anywhere in your custom code to list all the cron jobs that are currently running:
0 commit comments