Skip to content

Commit 882b355

Browse files
committed
Scheduled jobs
1 parent b6b8a6f commit 882b355

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

1. Magento Architecture and Customization Techniques/6. Configure event observers and scheduled jobs.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,61 @@ Example:
8080

8181
### Demonstrate how to configure a scheduled job
8282

83-
`cron_groups.xml` - store view scope:
8483

84+
##### Cron groups
85+
86+
A cron group is a logical group that enables you to easily run cron for more than one process at a time.
87+
Most Magento modules use the default cron group.
88+
89+
To declare new group and specify settings, create `<module>/etc/cron_groups.xml` file (store view scope):
90+
91+
```xml
92+
<?xml version="1.0"?>
93+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/cron_groups.xsd">
94+
<group id="default">
95+
<schedule_generate_every>15</schedule_generate_every>
96+
<schedule_ahead_for>20</schedule_ahead_for>
97+
<schedule_lifetime>15</schedule_lifetime>
98+
<history_cleanup_every>10</history_cleanup_every>
99+
<history_success_lifetime>10080</history_success_lifetime>
100+
<history_failure_lifetime>10080</history_failure_lifetime>
101+
<use_separate_process>0</use_separate_process>
102+
</group>
103+
</config>
104+
```
105+
106+
Existing groups:
85107
- default (no separate process)
86108
- index - mview, targetrule
87109
- catalog_event - catalog_event_status_checker - mark event open/closed
88110
- consumers - consumers_runner if configured to run by cron. `bin/magento queue:consumers:start`. PID file var/{$consumer}.pid
89111
- staging - staging_apply_version, staging_remove_updates, staging_synchronize_entities_period
90112
- ddg_automation (dotmailer)
91113

92-
```
93-
<group id="NAME">
94-
<job name="NAME" instance="CLASS" method="METHOD">
114+
##### crontab.xml
115+
116+
`crontab.xml` file is used to execute an action on schedule.
117+
This file always located in the <module>/etc/ folder (not in <module>/etc/{area}/)!
118+
119+
```xml
120+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
121+
<group id="GROUP_NAME">
122+
<job name="CRON_JOB_UNIQUE_ID" instance="CLASS" method="METHOD">
95123
<config_path>some/config/path</config_path>
96124
</job>
97125
<job name="NAME" instance="CLASS" method="METHOD">
98126
<schedule>* * * * *</config_path>
99127
</job>
100128
</group>
129+
</config>
101130
```
102131

103132
run:
104133

105134
- magento cron:run [–group=”"]
106135
- pub/cron.php?[group=<name>] in a web browser, protect with basic auth
107136

137+
Stack trace:
108138
```
109139
\Magento\Cron\Console\Command\CronCommand::execute
110140
\Magento\Framework\App\Cron::launch
@@ -116,8 +146,8 @@ generate
116146
check for standalone process
117147
```
118148

119-
\Magento\Cron\Model\Config\Data extends \Magento\Cron\Model\Config\Data
120-
- merges \Magento\Cron\Model\Config\Reader\Db::get from Database
149+
[\Magento\Cron\Model\Config\Data](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Cron/Model/Config/Data.php) extends [\Magento\Cron\Model\Config\Data](https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Config/Data.php)
150+
- merges [\Magento\Cron\Model\Config\Reader\Db::get](https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Cron/Model/Config/Reader/Db.php#L51) from Database
121151

122152
Sample DB structure:
123153
```

0 commit comments

Comments
 (0)