0

I've to insert/update/delete some data in my custom tables in each 6HR. so i'm using a custom module with CRON and in that module i've written script to insert/update/delete the things.

So for automatically hitting the CRON as i R&D

(reference link:- https://www.cloudways.com/blog/magento-2-cron-job/) and found

that i need to follow following steps :-

1- Login on the server as Super User

2- from the CLI,i need to hit "crontab -e"

3- then,i need to set following in this file

*/1 * * * * php -c <ini-file-path> <your Magento install dir>/bin/magento cron:run

*/1 * * * * php -c <ini-file-path> <your Magento install dir>/update/cron.php

*/1 * * * * php -c <ini-file-path> <your Magento install dir>/bin/magento setup:cron:run

Where "ini-file-path" => https://nimb.ws/fx1p70

"your Magento install dir"=> you can get via DIR

Which is exactly working for me,but by doing this indexing,orders etc crons are also automatically running but i want to run automatically my custom module "custom_cronjob" CRON only

Here is the screenshot:- https://nimb.ws/zoVApY

How can i achieve the same and avoid other CRONs?

Please help me!!!

0

Use n98-magerun2: https://github.com/netz98/n98-magerun2

It has a command called sys:cron:run <job-code> that lets you run only a specific job.

If you want to run you cronjob every 6 hours, you could edit the crontab file like this:

0 */6 * * * php -c <ini-file-path> <magento-dir>/n98-magerun2.phar sys:cron:run <job-code>

Here is a etc/crontab.xml file that you can insert to run your cronjob every 6 hours via the default Magento 2 cron function:

<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="my_cron_name" instance="Vendor\Module\Cron\File" method="execute">
            <schedule>0 */6 * * *</schedule>
        </job>
    </group>
</config>```
  • thanks for the update,will it execute automatically?is this extesnion?is there not any simpler way to execute my custom cron only? – wakar Ahamad Feb 12 at 10:41
  • This is a cron, so it will execute automatically as long as your server runs crontab. No, this is not an extension, please read the readme file in the repository. I think this way is very simple, what do you expect? – simonthesorcerer Feb 12 at 10:43
  • I expect something like Magento 1 cron.sh.shall i need to run "sys:cron:run <job-code>" manually?i want to hit my custom module cron automatically. – wakar Ahamad Feb 12 at 10:49
  • You could also install the Aoe_Scheduler module, go to the backend, disable all cronjobs but your own, and then run the default magento cron job. Imho, this would take longer... You run n98-magerun from the command line, have you read the Readme? Have you read how to use bin/magento? – simonthesorcerer Feb 12 at 11:00
  • sorrry!!! not getting you.i want to run my cron in each 6HR.how can i do that in Magento 2? – wakar Ahamad Feb 12 at 11:04
0

Create a custom cron job with custom cron group in your module. For more details plz visit: https://devdocs.magento.com/guides/v2.3/config-guide/cron/custom-cron-tut.html

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.