In Magento 2, cronjobs are defined in the crontab.xml
file of each module. Like every configuration in the Magento modules, the configuration of the cronjobs is easy to extend in custom modules. And that's what we will do in this recipe. We will create a new cronjob for our module.
Testing a cronjob is a bit tricky. You can wait while the cron will is executed, but in this recipe, we will see how we can trigger it for development purposes.
The workflow to create a new cronjob is mostly the same as working with event observers. We have to configure a new cronjob that will start a function in a configured class.
For the creation of a new cronjob, we will use the existing Packt_HelloWorld
module. Make sure you have the latest version installed.