Cron Job automatic execution is not wokring

I would like run cron job every 30 minutes to check items in the warehouse. We will update stock based on that. When I check by CLI tool

sw:cron:run ExampleStockManagerCron

. This is working as expected but the interval is not working. Is there any issue with any settings I need.

A plugin Root file:

addCron();
    }

    /**
     * Uninstall Plugin
     * 
     * Drop a table when plugin uninstall
     */
    public function uninstall(UninstallContext $context): void
    {
       $this->removeCron();
    }


    public function addCron()
    {
        $connection = $this->container->get('dbal_connection');
        $connection->insert(
            's_crontab',
            [
                'name' => 'ExampleStockManagerCron',
                'action' => 'ExampleStockManagerCron',
                'next' => new \DateTime(),
                'start' => null,
                '`interval`' => '100',
                'active' => 1,
                'end' => new \DateTime(),
                'pluginID' => null
            ],
            [
                'next' => 'datetime',
                'end' => 'datetime',
            ]
        );
    }
    public function removeCron()
    {
        $this->container->get('dbal_connection')->executeQuery('DELETE FROM s_crontab WHERE `name` = ?', [
            'ExampleStockManagerCron'
        ]);
return;
    }

   
}

?>

An XML for Cron Register:

        StockManagerCron
        Shopware_CronJob_ExampleStockManagerCron
        true
        300
        true

A Subscriber Class

 

 'ExampleStockManagerCron'
           
        ];

    } 


    /**
     * APIStockManagerCron() this will update stock based on API
     */
    public function ExampleStockManagerCron(\Shopware_Components_Cron_CronJob $job)
    {
               
       $responseMsg = 'Product id '.$value['ordernumber'].' updated with QTY '.$goodsQTY;
       $sql = "INSERT INTO `s_plugin_SwagAPI_log` (`id`, `response_desc`) VALUES (NULL, '$responseMsg')";            
       Shopware()->Db()->query($sql);       
        
    }
    
  
}

 

Hello,
you or your hoster must set up a regular job outside of Shopware that triggers the jobs within Shopware.

See section “Cronjob set up” Shopware 5 - Settings - System: Cronjobs

 

My cron inside plugin folder. How Should I call  in : 

 

*/15 * * * * wget -q http://www.myshop.com/backend/cron

You should prefer call the cronjob in the cli. php bin/console sw:cron:run

@Shyim‍  I thought you read my question. Its working in CLI but not call automatically.

Did you add the command to your servers crontab?
Shopware won’t call this automatically, you need to add a cron on your servers crontab. But this is not a shopware task at all.

 

This cron is executing a via CLI using command.  How to setup in server

Edit the users crontab:

crontab -e

In my servers crontab for the user „apache“ :

*/10 * * * * php /path_to_shopware/bin/console sw:cron:run > /dev/null

 

 

1 „Gefällt mir“

@sacrofano schrieb:

Edit the users crontab:

crontab -e

In my servers crontab for the user „apache“ :

*/10 * * * * php /path_to_shopware/bin/console sw:cron:run > /dev/null

 

 

Issue resolved path to shopware is missing  

There is a tutorial at https://www.easycron.com/cron-job-tutorials/how-to-set-up-cron-job-for-shopware , may be help you set cron job.

Thank you its working