2

I am new to Magento and trying to run Cron Job using module.

Here is my code
app/etc/modules/FQLabs_Automail.xml

<?xml version="1.0"?>
<config>
    <modules>
        <FQLabs_Automail>
            <active>true</active>
            <codePool>local</codePool>
        </FQLabs_Automail>
    </modules>
</config>

app/code/local/FQLabs_Automail/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
    <FQLabs_Automail>
        <version>0.1.0</version>    <!-- Version number of your module -->
    </FQLabs_Automail>
</modules>

<crontab>
    <jobs>
        <fqlabs_automail_send>
            <schedule>
                <cron_expr>*/5 * * * *</cron_expr>
            </schedule>
            <run>
                <model>automail/observer::doSomething</model>
            </run>
            </fqlabs_automail_send>
        </jobs>
    </crontab>

</config>

app/code/local/FQLabs_Automail/Models/observer.php

<?php 
class FQLabs_Automail_Model_Observer
{

    public function doSomething()
    {
        Mage::log("This is a cron run test", null, 'mylog.log');
        return $this;
    }


}

?>

After clearing cache and re indexing indexes, I hit (www.yourstore.com/cron.php) I have done everything right but still the log is not working. Please suggest some help. Module Link for Debug is here

4

app/code/local/FQLabs_Automail/Models/observer.php

is wrong, should be

app/code/local/FQLabs/Automail/Model/Observer.php

Refresh your configuration cache and you should then confirm that your module cron task is enabled in Magento, you can look for this in the database but I recommend you install the AOE Scheduler module http://fbrnc.net/blog/2011/03/magento-cron-scheduler

This will give you a detailed graphical view of all magento cron tasks, you should also see your cron job there if your module is configured properly.

You can manually schedule the cron job to run with AOE Scheduler and check your system log file for the output. Running cron.php from your browser will not necessarily run the job, as you have scheduled it to run every 5 mins.

This should help you troubleshoot the problem further.

  • No I do not see any entry in the database. I have written code properly so what mistake I am making? Last time I try to install that I was getting error. – Akshay Taru Aug 18 '15 at 10:49
  • remove the frontend router and define automail as suggested here. If that doesn't work zip your module up and upload it so that I can install and debug it. – paj Aug 18 '15 at 13:24
  • I have added the the link to download the module. Thanks – Akshay Taru Aug 18 '15 at 13:53
  • Your model class folder is named models instead of model. I have installed your module with the correct model folder name and it is working : 2015-08-18T14:26:01+00:00 DEBUG (7): FQLabs_Automail_Model_Observer – paj Aug 18 '15 at 14:27
  • I changed the file name. Did you Run cron.php after uploading module? – Akshay Taru Aug 18 '15 at 14:53
2

There are few issues in your model

Wrong Folder structure :

FQLabs_Automail is not single folder. It should be two different folders (FQLabs and Automail)

  • FQLabs call as Module NameSpace

  • Automail call as module Name

folder structure must be app/code/local/FQLabs/Automail for config.xml and Observer.php

app/code/local/FQLabs_Automail/etc/config.xml

should be

app/code/local/FQLabs/Automail/etc/config.xml

  • Models should be Model

observer.php be Observer.php

note: First letter of file should be Uppercase for model,block and helper ,controllers files

  • Thanks for correction. But code does not execute and create a log file – Akshay Taru Aug 18 '15 at 12:59
1

You need to define automail or Magento won't know what it's referenced to. In your config.xml, add the following:

<global>
   <models>
     <automail>
       <class>FQLabs_Automail_Model</class>
     </automail>
   </models>
</global>

Also, make sure that the logs are enabled, or else it will execute it, but never write to log.

  • I added this and yes logs are enabled but still not running. – Akshay Taru Aug 18 '15 at 10:43
  • Set up your Magento cron in your server cron, and make it run every minute. If it skips the time, Magento will mark it as Too late and won't run. (for example, if it's scheduled for 12.05, cron.sh has to run at that EXACT time) – Mayers Aug 18 '15 at 10:50
  • How to do it? And I hardly understood what you are trying to say that Too Late part of magento and How to set up and all. I am new in Magento – Akshay Taru Aug 18 '15 at 10:59
  • Google is your friend: support.xtento.com/wiki/Setting_up_the_Magento_cronjob – Mayers Aug 18 '15 at 11:24
  • Tried not working. – Akshay Taru Aug 18 '15 at 11:42
0

@Amit Bera's answer is correct.
Though if you want to use Magento's cron mechanic, you'll have to run cron.php (which is located in your root folder).
Try and run it every five minutes as a cronjob on your server, otherwise all Magento crons won't get registered in table cron_schedule (which is also a way of making sure your cron has been queued) and thus won't get triggered/executed.

  • I have tried to run cron.php manually by hitting the (www.yourstore.com/cron.php) but i do not see entry of that cron in the table cron_schedule. Please assist me to find whether Am I missing something. – Akshay Taru Aug 19 '15 at 6:54
  • but have you seen other crons being put into that table? – Julien Lachal Aug 19 '15 at 7:06
  • Lets continue discussion in chat – Akshay Taru Aug 19 '15 at 7:17
  • Yes I did, Now its working fine. I reinstalled AOE Scheduler and its cron, Now it is working fine, Thanks for the help – Akshay Taru Aug 19 '15 at 9:09
  • Alright, glad we managed to help, thumbs up always appreciated if it helped :) On a side note, try managing your crons server side, I know it can be a tedious task, but you're better off not cluttering Magento with tons of extensions. – Julien Lachal Aug 19 '15 at 9:25
-1

Try this

<global>
        <models>
            <automail>
                <class>FQLabs_Automail_Model</class>
            </automail>
        </models>
    </global>

    <frontend>
        <routers>
            <automail>
                <use>standard</use>
                <args>
                    <module>FQLabs_Automail</module>
                    <frontName>automail</frontName>
                </args>
            </automail>
        </routers>
    </frontend>
    <crontab>
        <jobs>
            <automail>
                <schedule>
                    <cron_expr>*/5 * * * *</cron_expr>
                </schedule>
                <run>
                    <model>automail/observer::doSomething</model>
                </run>
            </automail>
        </jobs>
    </crontab>

let me know if it's working or not?

  • a frontend router is not needed for this. – paj Aug 18 '15 at 13:20
  • @paj Of-course, we don't know where his using right? – Bojjaiah Aug 18 '15 at 13:27
  • what's wrong with this answer. why some one down vote for this? – Bojjaiah Aug 18 '15 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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