Can I trigger a cron job at the time of form submission?
Actually, I need to download a product pdf when the form gets submitted.
But my pdf file has a large amount of data. So the site gets slow down.
So that I have moved on to cron.
I've successfully set a cron by referring this link.
Here is my code,
/etc/crontab.xml
<?xml version="1.0"?>
<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="test_cronjob" instance="Test\CatalogPrint\Cron\Pdfdownload" method="execute">
<schedule>*/1 * * * *</schedule>
</job>
</group>
</config>
Cron/Pdfdownload.php
<?php
namespace Test\CatalogPrint\Cron;
class Pdfdownload extends \Magento\Framework\App\Action\Action
{
// doing my stuff on here
}
?>
And my form in the template file,
form.phtml
<form action="<?php echo $block->getFormAction() ?>" method="post" class="downloadPDF-account">
<label>Brochure Name: <input name="pdfname" type="text" /></label>
<input type="submit" value="Download" />
</form>
Actually now in this form action <?php echo $block->getFormAction() ?>'
, I given my controller path.
But I need to run my cron file (Test\CatalogPrint\Cron\Pdfdownload
) on here.
If I'm doing the same stuff on my controller, means it takes too much time and slow down my site.
Please help me. I am a novice in magento and I am stuck at this point. Thank you in advance!!