Magento 2.x – How to run a cronjob process by its code
If you need to run just a cron process per its code, the fastest way is using n98-magerun2 tool, if you are not familiar with, this is a command line suite of tools that make development easier.
You can install it with those basic steps:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Download the phar file in your magento root directory wget https://files.magerun.net/n98-magerun2.phar # Execute the downloaded .phar file chmod +x n98-magerun2.phar # Its recommended moving it into /usr/local/bin. # It will give an ability to run n98-magerun2.phar from any place of # your file system via command line. sudo mv n98-magerun2.phar /usr/local/bin/ # List all available commands just type the following line in your terminal n98-magerun2.phar list |
Once n98-magerun2 is installed properly, you will be able to run your cronjob as follows in yuor magento root directory:
|
1 |
n98-magerun2.phar sys:cron:run <job_code> |
For more information about n98-magerun2 you can review this link