Yes, you're right. The system doesn't know about all of the cron jobs defined inside Magento modules. They get exposed/scheduled/executed by a single system level crontab entry that runs the cron:run
Magento command.
System Level Cron
With Magento, you will have one system level cron job that kicks off cron:run
for Magento. This command is responsible for scheduling and executing cron jobs defined inside enabled modules.
Whenever it runs (usually every minute) it will schedule ahead (by adding records to the cron_schedule
table) module cron jobs based on the magento cron group settings used.
It will also execute jobs in the cron_schedule
table that have a schedule that falls within the correct window of time.
Example System Level Crontab Entry
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/magento2/var/log/magento.cron.log
Software Level Cron Groups/Jobs
Each Magento module has the ability to define software level cron jobs via the use of etc/crontab.xml
and etc/cron_groups.xml
Cron Groups
Below is an example of the default cron group that comes with Magento out-of-the-box. You do not need to add this file to your module unless you need custom control over the scheduling settings for a group of jobs. If you do need the control, you would add the file to your module and specify a new/unique group id.
Read this for more info:
Magento DevDocs - Specifying cron group options
[Vendor]/[ModuleName]/etc/cron_groups.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/cron_groups.xsd">
<group id="default">
<schedule_generate_every>15</schedule_generate_every>
<schedule_ahead_for>20</schedule_ahead_for>
<schedule_lifetime>15</schedule_lifetime>
<history_cleanup_every>10</history_cleanup_every>
<history_success_lifetime>60</history_success_lifetime>
<history_failure_lifetime>4320</history_failure_lifetime>
<use_separate_process>0</use_separate_process>
</group>
</config>
Cron Jobs
This is how you would define a cron job inside of a module. If you had defined a new cron group with custom settings, you would specify that group id when adding a job in this file. The name you give the job is what shows up for the value in cron_schedule.job_code
. The most basic way to specify a schedule is to use the <schedule/>
node. There are other options for specifying a schedule, which can be seen in the link below.
Read this for more info:
Magento DevDocs - Configure cron groups (their jobs)
[Vendor]/[ModuleName]/etc/crontab.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
<group id="default">
<job name="example_cron_job_code" instance="Vendor\YourModule\Cron\ExampleCronJob" method="execute">
<schedule>*/5 * * * *</schedule>
</job>>
</group>
</config>
References
Magento DevDocs - Configure and run cron
Magento DevDocs - Specifying cron group options
Magento DevDocs - Configure cron groups (their jobs)