Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 6abf7f0

Browse files
authored
Merge pull request #6863 from atwixfirster/cron-job-disable-cron-job
magento/devdocs#: Add a trick how a cron job can be disabled
2 parents ee1f086 + 48157f5 commit 6abf7f0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/guides/v2.3/config-guide/cron/custom-cron-ref.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,36 @@ where:
109109
| `history_failure_lifetime` | Time (in minutes) that the record of failed cron jobs are kept in the database. |
110110
| `use_separate_process` | Run this crongroup's jobs in a separate php process |
111111

112+
## Disable a cron job {#disable-cron-job}
113+
114+
Cron jobs do not have a `disable` feature like we have for [observers]({{ page.baseurl }}/extension-dev-guide/events-and-observers.html#subscribing-to-events). However, a cron job can be disabled by using the following technique: `schedule` a time that contains a date which will never happen.
115+
116+
For example, disable the `visitor_clean` cron job which defined in `Magento_Customer` module:
117+
118+
```xml
119+
...
120+
<group id="default">
121+
<job name="visitor_clean" instance="Magento\Customer\Model\Visitor" method="clean">
122+
<schedule>0 0 * * *</schedule>
123+
</job>
124+
</group>
125+
...
126+
```
127+
128+
To disable the `visitor_clean` cron job, create a custom module and rewrite the `visitor_clean` cron job `schedule`:
129+
130+
```xml
131+
...
132+
<group id="default">
133+
<job name="visitor_clean" instance="Magento\Customer\Model\Visitor" method="clean">
134+
<schedule>0 0 30 2 *</schedule>
135+
</job>
136+
</group>
137+
...
138+
```
139+
140+
Now, the `visitor_clean` cron job has been set to run at 00:00 on the 30th of February - at the date which will never occur.
141+
112142
{:.ref-header}
113143
Related topic
114144
[Tutorial---configure custom cron jobs and cron groups]({{ page.baseurl }}/config-guide/cron/custom-cron-tut.html)

0 commit comments

Comments
 (0)